├── .DS_Store ├── .cproject ├── .gitignore ├── .project ├── BLE └── scanner │ ├── README.md │ ├── ble1.c │ └── main.c ├── Documentation ├── BLE C++ Guide.pdf ├── C++ HTTP Server.pdf ├── ideas │ └── FastFlash │ │ └── README.md └── images │ └── arduino_debug.png ├── Kconfig ├── LICENSE ├── README.md ├── VisualStudioCode ├── README.md ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── arduino └── i2c │ └── i2cscanner │ ├── .cproject │ ├── .gitignore │ ├── .project │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── main │ ├── component.mk │ ├── i2cscanner.cpp │ └── main.c │ └── sdkconfig ├── c-utils ├── c_list.c ├── c_list.h ├── c_timeutils.c └── c_timeutils.h ├── cloud └── GCP │ └── JWT │ ├── base64url.cpp │ ├── base64url.h │ └── main.cpp ├── component.mk ├── console ├── main.cpp ├── test_argtable.cpp ├── test_console.cpp └── test_linenoise.cpp ├── cpp_utils ├── .gitignore ├── AWS.cpp ├── AWS.h ├── Apa102.cpp ├── Apa102.h ├── ArduinoBLE.md ├── Arduino_ESP32_BLE.library.properties ├── BLE2902.cpp ├── BLE2902.h ├── BLE2904.cpp ├── BLE2904.h ├── BLEAddress.cpp ├── BLEAddress.h ├── BLEAdvertisedDevice.cpp ├── BLEAdvertisedDevice.h ├── BLEAdvertising.cpp ├── BLEAdvertising.h ├── BLEBeacon.cpp ├── BLEBeacon.h ├── BLECharacteristic.cpp ├── BLECharacteristic.h ├── BLECharacteristicMap.cpp ├── BLEClient.cpp ├── BLEClient.h ├── BLEDescriptor.cpp ├── BLEDescriptor.h ├── BLEDescriptorMap.cpp ├── BLEDevice.cpp ├── BLEDevice.h ├── BLEEddystoneTLM.cpp ├── BLEEddystoneTLM.h ├── BLEEddystoneURL.cpp ├── BLEEddystoneURL.h ├── BLEExceptions.cpp ├── BLEExceptions.h ├── BLEHIDDevice.cpp ├── BLEHIDDevice.h ├── BLERemoteCharacteristic.cpp ├── BLERemoteCharacteristic.h ├── BLERemoteDescriptor.cpp ├── BLERemoteDescriptor.h ├── BLERemoteService.cpp ├── BLERemoteService.h ├── BLEScan.cpp ├── BLEScan.h ├── BLESecurity.cpp ├── BLESecurity.h ├── BLEServer.cpp ├── BLEServer.h ├── BLEService.cpp ├── BLEService.h ├── BLEServiceMap.cpp ├── BLEUUID.cpp ├── BLEUUID.h ├── BLEUtils.cpp ├── BLEUtils.h ├── BLEValue.cpp ├── BLEValue.h ├── BLEXML │ ├── Characteristics │ │ └── code │ │ │ ├── .gitignore │ │ │ ├── characteristics.txt │ │ │ └── run.sh │ ├── README.md │ └── Services │ │ └── code │ │ ├── .gitignore │ │ ├── run.sh │ │ └── services.txt ├── CMakeLists.txt ├── CPPNVS.cpp ├── CPPNVS.h ├── Console.cpp ├── Console.h ├── DesignNotes │ ├── BLECPP.md │ ├── README.md │ └── WebSockets.md ├── Doxyfile ├── FATFS_VFS.cpp ├── FATFS_VFS.h ├── FTPCallbacks.cpp ├── FTPServer.cpp ├── FTPServer.h ├── File.cpp ├── File.h ├── FileSystem.cpp ├── FileSystem.h ├── FreeRTOS.cpp ├── FreeRTOS.h ├── FreeRTOSTimer.cpp ├── FreeRTOSTimer.h ├── GPIO.cpp ├── GPIO.h ├── GeneralUtils.cpp ├── GeneralUtils.h ├── HIDKeyboardTypes.h ├── HIDTypes.h ├── HttpParser.cpp ├── HttpParser.h ├── HttpRequest.cpp ├── HttpRequest.h ├── HttpResponse.cpp ├── HttpResponse.h ├── HttpServer.cpp ├── HttpServer.h ├── I2C.cpp ├── I2C.h ├── I2S.cpp ├── I2S.h ├── IFTTT.cpp ├── IFTTT.h ├── JSON.cpp ├── JSON.h ├── Kconfig ├── MAX7219.cpp ├── MAX7219.h ├── MFRC522.cpp ├── MFRC522.h ├── MFRC522Debug.h ├── MMU.cpp ├── MMU.h ├── MPU6050.cpp ├── MPU6050.h ├── MRFC522Debug.cpp ├── Makefile.arduino ├── Memory.cpp ├── Memory.h ├── NeoPixelWiFiEventHandler.cpp ├── NeoPixelWiFiEventHandler.h ├── OV7670.cpp ├── OV7670.h ├── PCF8574.cpp ├── PCF8574.h ├── PCF8575.cpp ├── PCF8575.h ├── PWM.cpp ├── PWM.h ├── PubSubClient.cpp ├── PubSubClient.h ├── README.md ├── RESTClient.cpp ├── RESTClient.h ├── RMT.cpp ├── RMT.h ├── SOC.cpp ├── SOC.h ├── SPI.cpp ├── SPI.h ├── SSLUtils.cpp ├── SSLUtils.h ├── SmartLED.cpp ├── SmartLED.h ├── SockServ.cpp ├── SockServ.h ├── Socket.cpp ├── Socket.h ├── System.cpp ├── System.h ├── TFTP.cpp ├── TFTP.h ├── Task.cpp ├── Task.h ├── U8G2.cpp ├── U8G2.h ├── WS2812.cpp ├── WS2812.h ├── WebServer.cpp ├── WebServer.h ├── WebSocket.cpp ├── WebSocket.h ├── WebSocketFileTransfer.cpp ├── WebSocketFileTransfer.h ├── WiFi.cpp ├── WiFi.h ├── WiFiEventHandler.cpp ├── WiFiEventHandler.h ├── component.mk ├── library.properties ├── mainpage.dox └── tests │ ├── BLETests │ ├── Arduino │ │ ├── BLE_client │ │ │ └── BLE_client.ino │ │ ├── BLE_iBeacon │ │ │ └── BLE_iBeacon.ino │ │ ├── BLE_notify │ │ │ └── BLE_notify.ino │ │ ├── BLE_scan │ │ │ └── BLE_scan.ino │ │ ├── BLE_server │ │ │ └── BLE_server.ino │ │ ├── BLE_uart │ │ │ └── BLE_uart.ino │ │ ├── BLE_write │ │ │ └── BLE_write.ino │ │ └── security │ │ │ ├── BLE_client │ │ │ ├── BLE_client_encrypted │ │ │ │ └── BLE_client_encrypted.ino │ │ │ ├── BLE_client_numeric_confirmation │ │ │ │ └── BLE_client_numeric_confirmation.ino │ │ │ └── BLE_client_passkey │ │ │ │ └── BLE_client_passkey.ino │ │ │ ├── BLE_server │ │ │ ├── BLE_server_authorization │ │ │ │ └── BLE_server_authorization.ino │ │ │ ├── BLE_server_encrypted │ │ │ │ └── BLE_server_encrypted.ino │ │ │ ├── BLE_server_numeric_confirmation │ │ │ │ └── BLE_server_numeric_confirmation.ino │ │ │ └── BLE_server_passkey │ │ │ │ └── BLE_server_passkey.ino │ │ │ └── StaticPIN │ │ │ └── StaticPIN.ino │ ├── README.md │ ├── Sample-MLE-15.cpp │ ├── Sample1.cpp │ ├── SampleAsyncScan.cpp │ ├── SampleClient.cpp │ ├── SampleClientAndServer.cpp │ ├── SampleClientWithWiFi.cpp │ ├── SampleClient_Notify.cpp │ ├── SampleDisconnect.cpp │ ├── SampleHIDDevice.cpp │ ├── SampleHIDKeyboard.cpp │ ├── SampleKeyboardTypes.h │ ├── SampleNotify.cpp │ ├── SampleRead.cpp │ ├── SampleScan.cpp │ ├── SampleSensorTag.cpp │ ├── SampleServer.cpp │ ├── SampleWrite.cpp │ ├── main.cpp │ └── security │ │ ├── SampleClient_Encryption.cpp │ │ ├── SampleClient_authentication_numeric_confirmation.cpp │ │ ├── SampleClient_authentication_passkey.cpp │ │ ├── SampleServer_Encryption.cpp │ │ ├── SampleServer_authentication_numeric_confirmation.cpp │ │ ├── SampleServer_authentication_passkey.cpp │ │ ├── SampleServer_authorization.cpp │ │ └── app_main_security.cpp │ ├── MFRC522 │ ├── DumpInfo.cpp │ └── main.cpp │ ├── task_i2c_scanner.cpp │ ├── task_mdns.cpp │ ├── test_max7219.cpp │ ├── test_rest.cpp │ └── test_rest_ifttt.cpp ├── curl ├── README.md ├── build_files │ ├── README.md │ ├── component.mk │ └── lib │ │ └── curl_config.h └── fragments │ └── testCurl.c ├── eclipse └── c_includes.xml ├── error handling └── fragments │ └── espToError.c ├── filesystems ├── espfs │ ├── README.md │ ├── components │ │ └── espfs │ │ │ ├── component.mk │ │ │ ├── espfs.c │ │ │ ├── espfs.h │ │ │ └── espfsformat.h │ └── main.c └── sendZip │ ├── .gitignore │ ├── test.js │ └── ws_send_zip.js ├── gpio └── interrupts │ └── test_intr.c ├── hardware ├── LEDs │ └── ledDim.c ├── accelerometers │ ├── README.md │ └── mpu6050.c ├── ambient_light │ └── bh1750fvi.c ├── compass │ └── hmc5883l.c ├── displays │ ├── Adafruit-GFX-Library │ │ ├── API.md │ │ ├── Adafruit_GFX.cpp │ │ ├── Adafruit_GFX.h │ │ ├── Fonts │ │ │ ├── FreeMono12pt7b.h │ │ │ ├── FreeMono18pt7b.h │ │ │ ├── FreeMono24pt7b.h │ │ │ ├── FreeMono9pt7b.h │ │ │ ├── FreeMonoBold12pt7b.h │ │ │ ├── FreeMonoBold18pt7b.h │ │ │ ├── FreeMonoBold24pt7b.h │ │ │ ├── FreeMonoBold9pt7b.h │ │ │ ├── FreeMonoBoldOblique12pt7b.h │ │ │ ├── FreeMonoBoldOblique18pt7b.h │ │ │ ├── FreeMonoBoldOblique24pt7b.h │ │ │ ├── FreeMonoBoldOblique9pt7b.h │ │ │ ├── FreeMonoOblique12pt7b.h │ │ │ ├── FreeMonoOblique18pt7b.h │ │ │ ├── FreeMonoOblique24pt7b.h │ │ │ ├── FreeMonoOblique9pt7b.h │ │ │ ├── FreeSans12pt7b.h │ │ │ ├── FreeSans18pt7b.h │ │ │ ├── FreeSans24pt7b.h │ │ │ ├── FreeSans9pt7b.h │ │ │ ├── FreeSansBold12pt7b.h │ │ │ ├── FreeSansBold18pt7b.h │ │ │ ├── FreeSansBold24pt7b.h │ │ │ ├── FreeSansBold9pt7b.h │ │ │ ├── FreeSansBoldOblique12pt7b.h │ │ │ ├── FreeSansBoldOblique18pt7b.h │ │ │ ├── FreeSansBoldOblique24pt7b.h │ │ │ ├── FreeSansBoldOblique9pt7b.h │ │ │ ├── FreeSansOblique12pt7b.h │ │ │ ├── FreeSansOblique18pt7b.h │ │ │ ├── FreeSansOblique24pt7b.h │ │ │ ├── FreeSansOblique9pt7b.h │ │ │ ├── FreeSerif12pt7b.h │ │ │ ├── FreeSerif18pt7b.h │ │ │ ├── FreeSerif24pt7b.h │ │ │ ├── FreeSerif9pt7b.h │ │ │ ├── FreeSerifBold12pt7b.h │ │ │ ├── FreeSerifBold18pt7b.h │ │ │ ├── FreeSerifBold24pt7b.h │ │ │ ├── FreeSerifBold9pt7b.h │ │ │ ├── FreeSerifBoldItalic12pt7b.h │ │ │ ├── FreeSerifBoldItalic18pt7b.h │ │ │ ├── FreeSerifBoldItalic24pt7b.h │ │ │ ├── FreeSerifBoldItalic9pt7b.h │ │ │ ├── FreeSerifItalic12pt7b.h │ │ │ ├── FreeSerifItalic18pt7b.h │ │ │ ├── FreeSerifItalic24pt7b.h │ │ │ ├── FreeSerifItalic9pt7b.h │ │ │ └── TomThumb.h │ │ ├── README.md │ │ ├── component.mk │ │ ├── fontconvert │ │ │ ├── Makefile │ │ │ ├── fontconvert.c │ │ │ ├── fontconvert_win.md │ │ │ └── makefonts.sh │ │ ├── gfxfont.h │ │ ├── glcdfont.c │ │ ├── library.properties │ │ └── license.txt │ ├── Adafruit-PCD8544-Nokia-5110-LCD-library │ │ ├── .github │ │ │ ├── ISSUE_TEMPLATE.md │ │ │ └── PULL_REQUEST_TEMPLATE.md │ │ ├── API.md │ │ ├── Adafruit_PCD8544.cpp │ │ ├── Adafruit_PCD8544.h │ │ ├── README.txt │ │ ├── component.mk │ │ ├── examples │ │ │ └── pcdtest │ │ │ │ └── pcdtest.ino │ │ ├── library.properties │ │ └── license.txt │ ├── Adafruit_SSD1305-Library │ │ ├── .github │ │ │ ├── ISSUE_TEMPLATE.md │ │ │ └── PULL_REQUEST_TEMPLATE.md │ │ ├── Adafruit_SSD1305.cpp │ │ ├── Adafruit_SSD1305.h │ │ ├── README.txt │ │ ├── component.mk │ │ ├── examples │ │ │ └── ssd1305test │ │ │ │ └── ssd1305test.ino │ │ └── license.txt │ ├── Adafruit_SSD1306-Library │ │ ├── .github │ │ │ ├── ISSUE_TEMPLATE.md │ │ │ └── PULL_REQUEST_TEMPLATE.md │ │ ├── API.md │ │ ├── Adafruit_SSD1306.cpp │ │ ├── Adafruit_SSD1306.h │ │ ├── README.md │ │ ├── README.txt │ │ ├── component.mk │ │ ├── examples │ │ │ ├── main │ │ │ │ ├── component.mk │ │ │ │ ├── main.cpp │ │ │ │ └── tests.cpp │ │ │ ├── ssd1306_128x32_i2c │ │ │ │ └── ssd1306_128x32_i2c.ino │ │ │ ├── ssd1306_128x32_spi │ │ │ │ └── ssd1306_128x32_spi.ino │ │ │ ├── ssd1306_128x64_i2c │ │ │ │ └── ssd1306_128x64_i2c.ino │ │ │ └── ssd1306_128x64_spi │ │ │ │ └── ssd1306_128x64_spi.ino │ │ ├── library.properties │ │ └── license.txt │ ├── README.md │ ├── U8G2 │ │ ├── README.md │ │ ├── test_SSD1306.c │ │ ├── test_SSD1306_i2c.c │ │ ├── u8g2_esp32_hal.c │ │ └── u8g2_esp32_hal.h │ └── tests │ │ ├── main.c │ │ ├── scroll_text_pcd8544.cpp │ │ ├── scroll_text_ssd1306.cpp │ │ ├── simple_tests_ssd1306.cpp │ │ ├── test_pcd8544.cpp │ │ └── test_ssd1306.cpp ├── expanders │ └── mcp23017 │ │ ├── Adafruit_MCP23017.cpp │ │ └── Adafruit_MCP23017.h ├── gps │ ├── Fragments │ │ └── log_to_console.c │ └── gps │ │ ├── .cproject │ │ ├── .gitignore │ │ ├── .project │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.rst │ │ ├── components │ │ └── .gitignore │ │ ├── main │ │ ├── component.mk │ │ ├── gps.c │ │ └── main.c │ │ └── sdkconfig ├── infra_red │ └── receiver │ │ └── rmt_receiver.c ├── neopixels │ └── README.md ├── nrf24 │ └── utility │ │ ├── ESP_IDF │ │ ├── NRF24_spi.cpp │ │ ├── NRF24_spi.h │ │ ├── RF24_ESP_IDF.cpp │ │ ├── RF24_ESP_IDF.h │ │ ├── RF24_arch_config.h │ │ └── includes.h │ │ └── includes.h ├── rtc │ ├── README.md │ ├── ds1307.c │ └── pcf8523.c ├── servos │ └── servoSweep.c └── temperature and pressure │ └── bmp180.c ├── i2c └── scanner │ ├── README.md │ └── i2cscanner.c ├── memory ├── dma │ ├── DMA.cpp │ ├── DMA.h │ ├── DMA_GPIO.h │ ├── GPIODriver.cpp │ ├── GPIODriver.h │ ├── dma_console.cpp │ └── main.cpp └── esp32_memory.h ├── mongoose └── webserver │ ├── .gitignore │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── components │ └── .gitignore │ ├── main │ ├── component.mk │ ├── main.c │ ├── test1.html │ └── test1_html.h │ └── sdkconfig ├── networking ├── FTPServer │ ├── FTPCallbacks.cpp │ ├── FTPServer.cpp │ ├── FTPServer.h │ ├── README.md │ └── main.cpp ├── bootwifi │ ├── BootWiFi.cpp │ ├── BootWiFi.h │ ├── README.md │ ├── component.mk │ ├── selectAP.h │ └── selectAP.html ├── mqtt │ └── paho_mqtt_embedded_c │ │ ├── .cproject │ │ ├── .project │ │ ├── .settings │ │ ├── org.eclipse.cdt.core.prefs │ │ └── org.eclipse.cdt.ui.prefs │ │ ├── CONTRIBUTING.md │ │ ├── Debug │ │ ├── makefile │ │ ├── objects.mk │ │ ├── sources.mk │ │ └── src │ │ │ ├── MQTTDeserializeConnect.d │ │ │ └── subdir.mk │ │ ├── ESP32_Sample │ │ ├── main.c │ │ └── mqtt_paho.c │ │ ├── MQTTClient-C │ │ ├── samples │ │ │ └── linux │ │ │ │ ├── build.sh │ │ │ │ └── stdoutsub.c │ │ └── src │ │ │ ├── FreeRTOS │ │ │ ├── MQTTFreeRTOS.c │ │ │ └── MQTTFreeRTOS.h │ │ │ ├── MQTTClient.c │ │ │ ├── MQTTClient.h │ │ │ ├── cc3200 │ │ │ ├── MQTTCC3200.c │ │ │ └── MQTTCC3200.h │ │ │ ├── linux │ │ │ ├── MQTTLinux.c │ │ │ └── MQTTLinux.h │ │ │ └── samples │ │ │ └── FreeRTOS │ │ │ └── MQTTEcho.c │ │ ├── MQTTClient │ │ ├── samples │ │ │ ├── arduino │ │ │ │ └── Hello │ │ │ │ │ └── Hello.ino │ │ │ └── linux │ │ │ │ ├── build.sh │ │ │ │ ├── hello │ │ │ │ ├── hello.cpp │ │ │ │ ├── main.cpp │ │ │ │ ├── stdoutsub │ │ │ │ └── stdoutsub.cpp │ │ └── src │ │ │ ├── FP.h │ │ │ ├── MQTTClient.h │ │ │ ├── MQTTLogging.h │ │ │ ├── arduino │ │ │ ├── Countdown.h │ │ │ ├── IPStack.h │ │ │ └── WifiIPStack.h │ │ │ ├── linux │ │ │ └── linux.cpp │ │ │ └── mbed │ │ │ ├── MQTTEthernet.h │ │ │ └── MQTTSocket.h │ │ ├── MQTTPacket │ │ ├── samples │ │ │ ├── build │ │ │ ├── null.c │ │ │ ├── pub0sub1.c │ │ │ ├── pub0sub1_nb.c │ │ │ ├── qos0pub.c │ │ │ ├── transport.c │ │ │ └── transport.h │ │ ├── src │ │ │ ├── MQTTConnect.h │ │ │ ├── MQTTConnectClient.c │ │ │ ├── MQTTConnectServer.c │ │ │ ├── MQTTDeserializePublish.c │ │ │ ├── MQTTFormat.c │ │ │ ├── MQTTFormat.h │ │ │ ├── MQTTPacket.c │ │ │ ├── MQTTPacket.h │ │ │ ├── MQTTPublish.h │ │ │ ├── MQTTSerializePublish.c │ │ │ ├── MQTTSubscribe.h │ │ │ ├── MQTTSubscribeClient.c │ │ │ ├── MQTTSubscribeServer.c │ │ │ ├── MQTTUnsubscribe.h │ │ │ ├── MQTTUnsubscribeClient.c │ │ │ ├── MQTTUnsubscribeServer.c │ │ │ └── StackTrace.h │ │ └── test │ │ │ ├── build_test │ │ │ └── test1.c │ │ ├── Makefile │ │ ├── README.md │ │ ├── about.html │ │ ├── component.mk │ │ ├── edl-v10 │ │ ├── epl-v10 │ │ └── notice.html └── telnet │ ├── .gitignore │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── main │ ├── component.mk │ ├── main.c │ ├── telnet.c │ └── telnet.h │ └── sdkconfig ├── nvs └── fragments │ └── errorToString.c ├── partitions └── fragments │ ├── partitionSubtypeToString.c │ └── partitionTypeToString.c ├── posix ├── README.md └── posix_shims.c ├── pwm └── README.md ├── rmt ├── README.md └── fragments │ └── rmt_simple.c ├── skeletons └── cpp │ ├── README.md │ ├── main_helloworld.cpp │ └── main_network.cpp ├── sntp └── fragments │ └── sntp.c ├── sockets ├── client │ └── socketClient.c ├── server │ └── socket_server.c └── utilities │ └── socket_utils.c ├── spi └── fragments │ └── spi_transmit.c ├── tasks └── watchdogs │ ├── README.md │ └── main.cpp ├── tools ├── MMUTool │ └── MMUTool.html ├── bootloaderExamine │ ├── .gitignore │ └── main.cpp ├── esptool_libs │ ├── README.md │ └── nodejs │ │ ├── README.md │ │ ├── SampleFlasher │ │ └── flasher_stub.json │ │ ├── build.sh │ │ └── espjs.js └── sdkconfig_compare │ ├── README.md │ └── sdkconfig_compare.js ├── uart └── readLine.c ├── vfs ├── spiffs │ ├── spiffs_vfs.c │ └── spiffs_vfs.h └── vfs-skeleton │ ├── .gitignore │ ├── README.md │ └── main │ ├── main.c │ ├── vfsTest.c │ └── vfsTest.h └── wifi └── fragments ├── access-point.c ├── auth_mode_to_string.c └── connect_with_static_ip.c /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .cproject 3 | .settings/ 4 | 5 | # IDEs 6 | .vs/ 7 | .idea/ 8 | 9 | # CMake 10 | cmake-build-debug/ 11 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | esp32-snippets 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | 26 | 27 | -------------------------------------------------------------------------------- /BLE/scanner/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern void bt_task(void *ignore); 5 | 6 | 7 | void app_main(void) 8 | { 9 | xTaskCreatePinnedToCore(&bt_task, "btTask", 2048, NULL, 5, NULL, 0); 10 | } 11 | -------------------------------------------------------------------------------- /Documentation/BLE C++ Guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/Documentation/BLE C++ Guide.pdf -------------------------------------------------------------------------------- /Documentation/C++ HTTP Server.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/Documentation/C++ HTTP Server.pdf -------------------------------------------------------------------------------- /Documentation/ideas/FastFlash/README.md: -------------------------------------------------------------------------------- 1 | # FastFlash 2 | As we build ESP32 applications, we typically perform a compile, flash, test loop cycle. We compile an app, we flash the ESP32 with that app and then we test whether it works. We perform these actions over and over again. When we look at the time taken in each step, we see there is compile time on our PC and then the time taken to flash the PC. This story talks about the time taken to flash the PC. 3 | 4 | The ESP32 is typically configured to flash at 115200 kbps. This is 115200 bits per second. If we think that a typical ESP32 application is 800KBytes then this requires a transmission of: 5 | 6 | 800000 * 9 = 7.2 million bits = 62.5 seconds 7 | 8 | we can increase our baud rate up to 921600 = 7.8 seconds -------------------------------------------------------------------------------- /Documentation/images/arduino_debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/Documentation/images/arduino_debug.png -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | menu "nkolban's c++ wrappers" 2 | 3 | menuconfig NKOLBAN 4 | bool "nkolban's c++ wrappers" 5 | default y 6 | help 7 | Select this option to use nkolban's c++ wrappers. 8 | 9 | menuconfig NKOLBAN_BLE 10 | bool "bluetooth wrappers" 11 | depends on BT_ENABLED && NKOLBAN 12 | default y 13 | help 14 | Select this option to use nkolban's c++ bluetooth ble wrappers. 15 | 16 | menuconfig NKOLBAN_BLE2902 17 | bool "BLE2902" 18 | depends on NKOLBAN_BLE 19 | default y 20 | help 21 | Select this option to use nkolban's c++ bluetooth BLE2902 wrappers. 22 | 23 | endmenu -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP32 Snippets 2 | This repository is no longer being actively maintained. It was previously archived to make it read-only but, by request, has been un-archived so that others may continue to post comments and issues. However, please understand that issues raised are unlikely to be resolved against this repository. 3 | -------------------------------------------------------------------------------- /VisualStudioCode/README.md: -------------------------------------------------------------------------------- 1 | These are file for Microsoft Visual Studio Code and can be copied into your `.vscode` project folder. For more information on this area, see: 2 | 3 | * [VSCode JTAG Debugging of ESP32 - Part 2](https://gojimmypi.blogspot.com/2017/05/vscode-remote-jtag-debugging-of-esp32.html) 4 | * [Deous/VSC-Guide-for-esp32](https://github.com/Deous/VSC-Guide-for-esp32) -------------------------------------------------------------------------------- /VisualStudioCode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | 5 | { 6 | "name": "ESP32 OpenOCD launch", 7 | "type": "cppdbg", 8 | "request": "launch", 9 | "program": "./build/app-template.elf", 10 | "args": [], 11 | "stopAtEntry": true, 12 | "cwd": "${workspaceFolder}", 13 | "environment": [], 14 | "externalConsole": false, 15 | "MIMode": "gdb", 16 | "miDebuggerPath": "/opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb", 17 | "setupCommands": [ 18 | { 19 | "description": "Enable pretty-printing for gdb", 20 | "text": "-enable-pretty-printing", 21 | "ignoreFailures": true 22 | }, 23 | { 24 | "text": "target remote localhost:3333" 25 | }, 26 | { 27 | "text": "monitor reset halt" 28 | }, 29 | { 30 | "text": "flushregs" 31 | }, 32 | { 33 | "text": "thb app_main" 34 | } 35 | ], 36 | "logging": { 37 | "trace": true, 38 | "traceResponse": true, 39 | "engineLogging": true 40 | } 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /VisualStudioCode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | } -------------------------------------------------------------------------------- /VisualStudioCode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "menuconfig", 8 | "type": "shell", 9 | "command": "make menuconfig", 10 | "problemMatcher": [] 11 | }, 12 | { 13 | "label": "make", 14 | "type": "shell", 15 | "command": "make -j5", 16 | "group": { 17 | "kind": "build", 18 | "isDefault": true 19 | }, 20 | "problemMatcher": [] 21 | }, 22 | { 23 | "label": "flash", 24 | "type": "shell", 25 | "command": "make flash monitor", 26 | "problemMatcher": [] 27 | }, 28 | { 29 | "label": "monitor", 30 | "type": "shell", 31 | "command": "make monitor", 32 | "problemMatcher": [] 33 | }, 34 | { 35 | "label": "clean", 36 | "type": "shell", 37 | "command": "make clean", 38 | "problemMatcher": [] 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /arduino/i2c/i2cscanner/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | components/ 3 | sdkconfig.old 4 | -------------------------------------------------------------------------------- /arduino/i2c/i2cscanner/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | i2cscanner 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | 26 | 27 | -------------------------------------------------------------------------------- /arduino/i2c/i2cscanner/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := app-template 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /arduino/i2c/i2cscanner/README.md: -------------------------------------------------------------------------------- 1 | #I2CScanner 2 | Using the Arduino Wire class, execute an I2C scan across all the devices and see 3 | which ones respond. This is a poor mans version of an `i2cdetect` like tool. -------------------------------------------------------------------------------- /arduino/i2c/i2cscanner/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | include $(IDF_PATH)/make/component_common.mk 11 | -------------------------------------------------------------------------------- /arduino/i2c/i2cscanner/main/i2cscanner.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Scan for I2C devices. 3 | * 4 | * Scan for I2C devices using the Arduino Wire library. 5 | * 6 | * For additional details and documentation see: 7 | * * Free book on ESP32 - https://leanpub.com/kolban-ESP32 8 | * 9 | * 10 | * Neil Kolban 11 | * 12 | */ 13 | #include "Wire.h" 14 | #include "esp_log.h" 15 | #include "driver/gpio.h" 16 | 17 | #define SDAPIN (GPIO_NUM_22) 18 | #define SCLPIN (GPIO_NUM_23) 19 | 20 | static char tag[]="i2cscanner"; 21 | 22 | extern "C" { 23 | void I2CScanner(); 24 | } 25 | 26 | void I2CScanner() { 27 | ESP_LOGI(tag, "I2C scanning with SDA=%d, CLK=%d", SDAPIN, SCLPIN); 28 | Wire.begin(SDAPIN, SCLPIN); 29 | int address; 30 | int foundCount = 0; 31 | for (address=1; address<127; address++) { 32 | Wire.beginTransmission(address); 33 | uint8_t error = Wire.endTransmission(); 34 | if (error == 0) { 35 | foundCount++; 36 | ESP_LOGI(tag, "Found device at 0x%.2x", address); 37 | } 38 | } 39 | ESP_LOGI(tag, "Found %d I2C devices by scanning.", foundCount); 40 | } 41 | -------------------------------------------------------------------------------- /arduino/i2c/i2cscanner/main/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Scan for I2C devices. 3 | * 4 | * Scan for I2C devices using the Arduino Wire library. 5 | * 6 | * For additional details and documentation see: 7 | * * Free book on ESP32 - https://leanpub.com/kolban-ESP32 8 | * 9 | * 10 | * Neil Kolban 11 | * 12 | */ 13 | 14 | #include "freertos/FreeRTOS.h" 15 | #include "esp_wifi.h" 16 | #include "esp_system.h" 17 | #include "esp_event.h" 18 | #include "esp_event_loop.h" 19 | #include "nvs_flash.h" 20 | #include "driver/gpio.h" 21 | #include "esp_log.h" 22 | 23 | extern void I2CScanner(); 24 | 25 | esp_err_t event_handler(void *ctx, system_event_t *event) 26 | { 27 | return ESP_OK; 28 | } 29 | 30 | int app_main(void) 31 | { 32 | nvs_flash_init(); 33 | system_init(); 34 | tcpip_adapter_init(); 35 | ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); 36 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); 37 | ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); 38 | ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); 39 | ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); 40 | I2CScanner(); 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /c-utils/c_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_utils.h 3 | * 4 | * Created on: Nov 15, 2016 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_C_LIST_H_ 9 | #define COMPONENTS_C_LIST_H_ 10 | 11 | typedef struct _list_t { 12 | void *value; 13 | struct _list_t *next; 14 | struct _list_t *prev; 15 | } list_t; 16 | 17 | list_t *list_createList(); 18 | void list_deleteList(list_t *pList, int withFree); 19 | void list_insert(list_t *pList, void *value); 20 | void list_remove(list_t *pList, list_t *pEntry, int withFree); 21 | list_t *list_next(list_t *pList); 22 | void list_removeByValue(list_t *pList, void *value, int withFree); 23 | list_t *list_first(list_t *pList); 24 | void list_insert_after(list_t *pEntry, void *value); 25 | void list_insert_before(list_t *pEntry, void *value); 26 | void *list_get_value(list_t *pList); 27 | #endif /* COMPONENTS_C_LIST_H_ */ 28 | -------------------------------------------------------------------------------- /c-utils/c_timeutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_timeutils.h 3 | * 4 | * Created on: Nov 26, 2016 5 | * Author: kolban 6 | */ 7 | 8 | #if !defined(_C_TIMEUTILS_H_) 9 | #define _C_TIMEUTILS_H_ 10 | #include 11 | #include 12 | 13 | struct timeval timeval_add(struct timeval *a, struct timeval *b); 14 | void timeval_addMsecs(struct timeval *a, uint32_t msecs); 15 | uint32_t timeval_durationBeforeNow(struct timeval *a); 16 | uint32_t timeval_durationFromNow(struct timeval *a); 17 | struct timeval timeval_sub(struct timeval *a, struct timeval *b); 18 | uint32_t timeval_toMsecs(struct timeval *a); 19 | 20 | #endif /* _C_TIMEUTILS_H_ */ 21 | -------------------------------------------------------------------------------- /cloud/GCP/JWT/base64url.h: -------------------------------------------------------------------------------- 1 | // https://raw.githubusercontent.com/zhicheng/base64/master/base64.h 2 | #ifndef __BASE64URL_H__ 3 | #define __BASE64URL_H__ 4 | 5 | enum {BASE64_OK = 0, BASE64_INVALID}; 6 | 7 | #define BASE64_ENCODE_OUT_SIZE(s) (((s) + 2) / 3 * 4) 8 | #define BASE64_DECODE_OUT_SIZE(s) (((s)) / 4 * 3) 9 | 10 | int base64url_encode(const unsigned char *in, unsigned int inlen, char *out); 11 | 12 | int base64url_decode(const char *in, unsigned int inlen, unsigned char *out); 13 | 14 | 15 | #endif /* __BASE64URL_H__ */ 16 | -------------------------------------------------------------------------------- /component.mk: -------------------------------------------------------------------------------- 1 | c := cpp_utils 2 | COMPONENT_EXTRA_INCLUDES := $(realpath $c) 3 | COMPONENT_ADD_INCLUDEDIRS := $c 4 | COMPONENT_SRCDIRS := $c 5 | 6 | $(call compile_only_if,$(CONFIG_NKOLBAN), \ 7 | $c/Task.o \ 8 | $c/FreeRTOS.o \ 9 | $c/GeneralUtils.o \ 10 | ) 11 | 12 | $(call compile_only_if,$(CONFIG_NKOLBAN_BLE), \ 13 | $c/BLEAddress.o \ 14 | $c/BLEAdvertisedDevice.o \ 15 | $c/BLEAdvertising.o \ 16 | $c/BLECharacteristic.o \ 17 | $c/BLECharacteristicCallbacks.o \ 18 | $c/BLECharacteristicMap.o \ 19 | $c/BLEClient.o \ 20 | $c/BLEDescriptor.o \ 21 | $c/BLEDescriptorMap.o \ 22 | $c/BLEDevice.o \ 23 | $c/BLERemoteCharacteristic.o \ 24 | $c/BLERemoteDescriptor.o \ 25 | $c/BLERemoteService.o \ 26 | $c/BLEScan.o \ 27 | $c/BLEServer.o \ 28 | $c/BLEService.o \ 29 | $c/BLEServiceMap.o \ 30 | $c/BLEUUID.o \ 31 | $c/BLEUtils.o \ 32 | $c/BLEValue.o \ 33 | ) 34 | 35 | $(call compile_only_if,$(CONFIG_NKOLBAN_BLE2902),$c/BLE2902.o) 36 | -------------------------------------------------------------------------------- /console/main.cpp: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | void app_main(void); 3 | } 4 | 5 | extern void test_linenoise(); 6 | extern void test_argtable(); 7 | extern void test_console(); 8 | 9 | void app_main(void) 10 | { 11 | //test_linenoise(); 12 | //test_argtable(); 13 | test_console(); 14 | } 15 | -------------------------------------------------------------------------------- /console/test_linenoise.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Test of linenoise 3 | * 4 | * @author Neil Kolban 5 | * @date 2018-05-26 6 | * 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "sdkconfig.h" 16 | 17 | void test_linenoise(void) 18 | { 19 | // Boiler plate setup for using linenoise 20 | setvbuf(stdin, NULL, _IONBF, 0); 21 | setvbuf(stdout, NULL, _IONBF, 0); 22 | esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); 23 | esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); 24 | uart_driver_install((uart_port_t)CONFIG_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0); 25 | esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); 26 | 27 | 28 | linenoiseClearScreen(); 29 | linenoiseSetMultiLine(0); 30 | 31 | while(1) { 32 | char* line = linenoise("Enter command > "); 33 | if (line != NULL) { 34 | printf("Got: %s\n", line); 35 | linenoiseHistoryAdd(line); 36 | linenoiseFree(line); 37 | } // Line is not null 38 | printf("--------------\n"); 39 | } // End while loop 40 | } 41 | -------------------------------------------------------------------------------- /cpp_utils/.gitignore: -------------------------------------------------------------------------------- 1 | /docs/ 2 | -------------------------------------------------------------------------------- /cpp_utils/AWS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AWS.h 3 | * 4 | * Created on: May 31, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_AWS_H_ 9 | #define COMPONENTS_AWS_H_ 10 | #include "sdkconfig.h" 11 | #ifdef CONFIG_AWS_IOT_SDK 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /** 18 | * @brief AWS IoT access. 19 | */ 20 | class AWS { 21 | public: 22 | AWS(); 23 | virtual ~AWS(); 24 | 25 | void connect(std::string clientId); 26 | void disconnect(); 27 | static std::string errorToString(IoT_Error_t err); // Convert an AWS IoT error code to a string representation. 28 | void init(std::string host=CONFIG_AWS_IOT_MQTT_HOST, uint16_t port=CONFIG_AWS_IOT_MQTT_PORT); 29 | void publish(std::string topic, std::string payload, QoS qos = QOS0); 30 | void subscribe(std::string topic); 31 | void unsubscribe(std::string topic); 32 | 33 | private: 34 | AWS_IoT_Client m_client; 35 | }; 36 | #endif // CONFIG_AWS_IOT_SDK 37 | #endif /* COMPONENTS_AWS_H_ */ 38 | -------------------------------------------------------------------------------- /cpp_utils/Apa102.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Apa102.cpp 3 | * 4 | * Created on: Oct 22, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #include "Apa102.h" 9 | 10 | Apa102::Apa102() { 11 | } 12 | 13 | Apa102::~Apa102() { 14 | 15 | } 16 | 17 | 18 | void Apa102::init() { 19 | mySPI.init(); 20 | } 21 | 22 | /** 23 | * @brief Show the pixels on an APA102 device. 24 | * The pixels that have been set are pushed to the APA102 devices. 25 | */ 26 | void Apa102::show() { 27 | // We follow the data sheet for the APA102. To signify a new stream of data 28 | // we send 32bits of 0 value. Following that are 4 bytes of color data. The 29 | // data is 0b111 nnnnn where `nnnnn` is the brightness of the pixels. 30 | // The following data is 8 bits for blue, 8 bits for green and 8 bits for red. 31 | 32 | // Send APA102 start. 33 | mySPI.transferByte(0x0); 34 | mySPI.transferByte(0x0); 35 | mySPI.transferByte(0x0); 36 | mySPI.transferByte(0x0); 37 | 38 | double brigthnessScale = getBrightness() / 100.0; 39 | // Loop over all the pixels in the pixels array to set the colors. 40 | for (uint16_t i = 0; i < m_pixelCount; i++) { 41 | mySPI.transferByte(0xff); // Maximum brightness 42 | mySPI.transferByte(m_pixels[i].blue * brigthnessScale); 43 | mySPI.transferByte(m_pixels[i].green * brigthnessScale); 44 | mySPI.transferByte(m_pixels[i].red * brigthnessScale); 45 | } // End loop over all the pixels. 46 | } // show 47 | -------------------------------------------------------------------------------- /cpp_utils/Apa102.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Apa102.h 3 | * 4 | * Created on: Oct 22, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_APA102_H_ 9 | #define COMPONENTS_CPP_UTILS_APA102_H_ 10 | 11 | #include "SmartLED.h" 12 | #include "SPI.h" 13 | 14 | class Apa102: public SmartLED { 15 | public: 16 | Apa102(); 17 | virtual ~Apa102(); 18 | void init(); 19 | void show(); 20 | private: 21 | SPI mySPI; 22 | }; 23 | 24 | #endif /* COMPONENTS_CPP_UTILS_APA102_H_ */ 25 | -------------------------------------------------------------------------------- /cpp_utils/Arduino_ESP32_BLE.library.properties: -------------------------------------------------------------------------------- 1 | name=ESP32 BLE Arduino 2 | version=0.4.3 3 | author=Neil Kolban 4 | maintainer=Neil Kolban 5 | sentence=BLE functions for ESP32 6 | paragraph=This library provides an implementation Bluetooth Low Energy support for the ESP32 using the Arduino platform. 7 | category=Communication 8 | url=https://github.com/nkolban/ESP32_BLE_Arduino 9 | architectures=esp32 10 | includes=BLE.h, BLEUtils.h, BLEScan.h, BLEAdvertisedDevice.h -------------------------------------------------------------------------------- /cpp_utils/BLE2902.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BLE2902.cpp 3 | * 4 | * Created on: Jun 25, 2017 5 | * Author: kolban 6 | */ 7 | 8 | /* 9 | * See also: 10 | * https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml 11 | */ 12 | #include "sdkconfig.h" 13 | #if defined(CONFIG_BT_ENABLED) 14 | 15 | #include "BLE2902.h" 16 | 17 | BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t) 0x2902)) { 18 | uint8_t data[2] = { 0, 0 }; 19 | setValue(data, 2); 20 | } // BLE2902 21 | 22 | 23 | /** 24 | * @brief Get the notifications value. 25 | * @return The notifications value. True if notifications are enabled and false if not. 26 | */ 27 | bool BLE2902::getNotifications() { 28 | return (getValue()[0] & (1 << 0)) != 0; 29 | } // getNotifications 30 | 31 | 32 | /** 33 | * @brief Get the indications value. 34 | * @return The indications value. True if indications are enabled and false if not. 35 | */ 36 | bool BLE2902::getIndications() { 37 | return (getValue()[0] & (1 << 1)) != 0; 38 | } // getIndications 39 | 40 | 41 | /** 42 | * @brief Set the indications flag. 43 | * @param [in] flag The indications flag. 44 | */ 45 | void BLE2902::setIndications(bool flag) { 46 | uint8_t *pValue = getValue(); 47 | if (flag) pValue[0] |= 1 << 1; 48 | else pValue[0] &= ~(1 << 1); 49 | } // setIndications 50 | 51 | 52 | /** 53 | * @brief Set the notifications flag. 54 | * @param [in] flag The notifications flag. 55 | */ 56 | void BLE2902::setNotifications(bool flag) { 57 | uint8_t *pValue = getValue(); 58 | if (flag) pValue[0] |= 1 << 0; 59 | else pValue[0] &= ~(1 << 0); 60 | } // setNotifications 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /cpp_utils/BLE2902.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BLE2902.h 3 | * 4 | * Created on: Jun 25, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_BLE2902_H_ 9 | #define COMPONENTS_CPP_UTILS_BLE2902_H_ 10 | #include "sdkconfig.h" 11 | #if defined(CONFIG_BT_ENABLED) 12 | 13 | #include "BLEDescriptor.h" 14 | 15 | /** 16 | * @brief Descriptor for Client Characteristic Configuration. 17 | * 18 | * This is a convenience descriptor for the Client Characteristic Configuration which has a UUID of 0x2902. 19 | * 20 | * See also: 21 | * https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml 22 | */ 23 | class BLE2902: public BLEDescriptor { 24 | public: 25 | BLE2902(); 26 | bool getNotifications(); 27 | bool getIndications(); 28 | void setNotifications(bool flag); 29 | void setIndications(bool flag); 30 | 31 | }; // BLE2902 32 | 33 | #endif /* CONFIG_BT_ENABLED */ 34 | #endif /* COMPONENTS_CPP_UTILS_BLE2902_H_ */ 35 | -------------------------------------------------------------------------------- /cpp_utils/BLEAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BLEAddress.h 3 | * 4 | * Created on: Jul 2, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_BLEADDRESS_H_ 9 | #define COMPONENTS_CPP_UTILS_BLEADDRESS_H_ 10 | #include "sdkconfig.h" 11 | #if defined(CONFIG_BT_ENABLED) 12 | #include // ESP32 BLE 13 | #include 14 | 15 | 16 | /** 17 | * @brief A %BLE device address. 18 | * 19 | * Every %BLE device has a unique address which can be used to identify it and form connections. 20 | */ 21 | class BLEAddress { 22 | public: 23 | BLEAddress(esp_bd_addr_t address); 24 | BLEAddress(std::string stringAddress); 25 | bool equals(BLEAddress otherAddress); 26 | esp_bd_addr_t* getNative(); 27 | std::string toString(); 28 | 29 | private: 30 | esp_bd_addr_t m_address; 31 | }; 32 | 33 | #endif /* CONFIG_BT_ENABLED */ 34 | #endif /* COMPONENTS_CPP_UTILS_BLEADDRESS_H_ */ 35 | -------------------------------------------------------------------------------- /cpp_utils/BLEBeacon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BLEBeacon2.h 3 | * 4 | * Created on: Jan 4, 2018 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_BLEBEACON_H_ 9 | #define COMPONENTS_CPP_UTILS_BLEBEACON_H_ 10 | #include "BLEUUID.h" 11 | /** 12 | * @brief Representation of a beacon. 13 | * See: 14 | * * https://en.wikipedia.org/wiki/IBeacon 15 | */ 16 | class BLEBeacon { 17 | private: 18 | struct { 19 | uint16_t manufacturerId; 20 | uint8_t subType; 21 | uint8_t subTypeLength; 22 | uint8_t proximityUUID[16]; 23 | uint16_t major; 24 | uint16_t minor; 25 | int8_t signalPower; 26 | } __attribute__((packed)) m_beaconData; 27 | public: 28 | BLEBeacon(); 29 | std::string getData(); 30 | uint16_t getMajor(); 31 | uint16_t getMinor(); 32 | uint16_t getManufacturerId(); 33 | BLEUUID getProximityUUID(); 34 | int8_t getSignalPower(); 35 | void setData(std::string data); 36 | void setMajor(uint16_t major); 37 | void setMinor(uint16_t minor); 38 | void setManufacturerId(uint16_t manufacturerId); 39 | void setProximityUUID(BLEUUID uuid); 40 | void setSignalPower(int8_t signalPower); 41 | }; // BLEBeacon 42 | 43 | #endif /* COMPONENTS_CPP_UTILS_BLEBEACON_H_ */ 44 | -------------------------------------------------------------------------------- /cpp_utils/BLEEddystoneTLM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BLEEddystoneTLM.cpp 3 | * 4 | * Created on: Mar 12, 2018 5 | * Author: pcbreflux 6 | */ 7 | 8 | #ifndef _BLEEddystoneTLM_H_ 9 | #define _BLEEddystoneTLM_H_ 10 | #include "BLEUUID.h" 11 | 12 | #define EDDYSTONE_TLM_FRAME_TYPE 0x20 13 | 14 | /** 15 | * @brief Representation of a beacon. 16 | * See: 17 | * * https://github.com/google/eddystone 18 | */ 19 | class BLEEddystoneTLM { 20 | public: 21 | BLEEddystoneTLM(); 22 | std::string getData(); 23 | BLEUUID getUUID(); 24 | uint8_t getVersion(); 25 | uint16_t getVolt(); 26 | float getTemp(); 27 | uint32_t getCount(); 28 | uint32_t getTime(); 29 | std::string toString(); 30 | void setData(std::string data); 31 | void setUUID(BLEUUID l_uuid); 32 | void setVersion(uint8_t version); 33 | void setVolt(uint16_t volt); 34 | void setTemp(float temp); 35 | void setCount(uint32_t advCount); 36 | void setTime(uint32_t tmil); 37 | 38 | private: 39 | uint16_t beaconUUID; 40 | struct { 41 | uint8_t frameType; 42 | uint8_t version; 43 | uint16_t volt; 44 | uint16_t temp; 45 | uint32_t advCount; 46 | uint32_t tmil; 47 | } __attribute__((packed)) m_eddystoneData; 48 | 49 | }; // BLEEddystoneTLM 50 | 51 | #endif /* _BLEEddystoneTLM_H_ */ 52 | -------------------------------------------------------------------------------- /cpp_utils/BLEEddystoneURL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BLEEddystoneURL.cpp 3 | * 4 | * Created on: Mar 12, 2018 5 | * Author: pcbreflux 6 | */ 7 | 8 | #ifndef _BLEEddystoneURL_H_ 9 | #define _BLEEddystoneURL_H_ 10 | #include "BLEUUID.h" 11 | 12 | #define EDDYSTONE_URL_FRAME_TYPE 0x10 13 | 14 | /** 15 | * @brief Representation of a beacon. 16 | * See: 17 | * * https://github.com/google/eddystone 18 | */ 19 | class BLEEddystoneURL { 20 | public: 21 | BLEEddystoneURL(); 22 | std::string getData(); 23 | BLEUUID getUUID(); 24 | int8_t getPower(); 25 | std::string getURL(); 26 | std::string getDecodedURL(); 27 | void setData(std::string data); 28 | void setUUID(BLEUUID l_uuid); 29 | void setPower(int8_t advertisedTxPower); 30 | void setURL(std::string url); 31 | 32 | private: 33 | uint16_t beaconUUID; 34 | uint8_t lengthURL; 35 | struct { 36 | uint8_t frameType; 37 | int8_t advertisedTxPower; 38 | uint8_t url[16]; 39 | } __attribute__((packed)) m_eddystoneData; 40 | 41 | }; // BLEEddystoneURL 42 | 43 | #endif /* _BLEEddystoneURL_H_ */ 44 | -------------------------------------------------------------------------------- /cpp_utils/BLEExceptions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BLExceptions.cpp 3 | * 4 | * Created on: Nov 27, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #include "BLEExceptions.h" 9 | 10 | -------------------------------------------------------------------------------- /cpp_utils/BLEExceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BLExceptions.h 3 | * 4 | * Created on: Nov 27, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_BLEEXCEPTIONS_H_ 9 | #define COMPONENTS_CPP_UTILS_BLEEXCEPTIONS_H_ 10 | #include "sdkconfig.h" 11 | 12 | #if CONFIG_CXX_EXCEPTIONS != 1 13 | #error "C++ exception handling must be enabled within make menuconfig. See Compiler Options > Enable C++ Exceptions." 14 | #endif 15 | 16 | #include 17 | 18 | 19 | class BLEDisconnectedException : public std::exception { 20 | const char* what() const throw () { 21 | return "BLE Disconnected"; 22 | } 23 | }; 24 | 25 | class BLEUuidNotFoundException : public std::exception { 26 | const char* what() const throw () { 27 | return "No such UUID"; 28 | } 29 | }; 30 | 31 | #endif /* COMPONENTS_CPP_UTILS_BLEEXCEPTIONS_H_ */ 32 | -------------------------------------------------------------------------------- /cpp_utils/BLEUUID.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BLEUUID.h 3 | * 4 | * Created on: Jun 21, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_BLEUUID_H_ 9 | #define COMPONENTS_CPP_UTILS_BLEUUID_H_ 10 | #include "sdkconfig.h" 11 | #if defined(CONFIG_BT_ENABLED) 12 | #include 13 | #include 14 | 15 | /** 16 | * @brief A model of a %BLE UUID. 17 | */ 18 | class BLEUUID { 19 | public: 20 | BLEUUID(std::string uuid); 21 | BLEUUID(uint16_t uuid); 22 | BLEUUID(uint32_t uuid); 23 | BLEUUID(esp_bt_uuid_t uuid); 24 | BLEUUID(uint8_t* pData, size_t size, bool msbFirst); 25 | BLEUUID(esp_gatt_id_t gattId); 26 | BLEUUID(); 27 | uint8_t bitSize(); // Get the number of bits in this uuid. 28 | bool equals(BLEUUID uuid); 29 | esp_bt_uuid_t* getNative(); 30 | BLEUUID to128(); 31 | std::string toString(); 32 | static BLEUUID fromString(std::string uuid); // Create a BLEUUID from a string 33 | 34 | private: 35 | esp_bt_uuid_t m_uuid; // The underlying UUID structure that this class wraps. 36 | bool m_valueSet = false; // Is there a value set for this instance. 37 | }; // BLEUUID 38 | #endif /* CONFIG_BT_ENABLED */ 39 | #endif /* COMPONENTS_CPP_UTILS_BLEUUID_H_ */ 40 | -------------------------------------------------------------------------------- /cpp_utils/BLEValue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BLEValue.h 3 | * 4 | * Created on: Jul 17, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_BLEVALUE_H_ 9 | #define COMPONENTS_CPP_UTILS_BLEVALUE_H_ 10 | #include "sdkconfig.h" 11 | #if defined(CONFIG_BT_ENABLED) 12 | #include 13 | 14 | /** 15 | * @brief The model of a %BLE value. 16 | */ 17 | class BLEValue { 18 | public: 19 | BLEValue(); 20 | void addPart(std::string part); 21 | void addPart(uint8_t* pData, size_t length); 22 | void cancel(); 23 | void commit(); 24 | uint8_t* getData(); 25 | size_t getLength(); 26 | uint16_t getReadOffset(); 27 | std::string getValue(); 28 | void setReadOffset(uint16_t readOffset); 29 | void setValue(std::string value); 30 | void setValue(uint8_t* pData, size_t length); 31 | 32 | private: 33 | std::string m_accumulation; 34 | uint16_t m_readOffset; 35 | std::string m_value; 36 | 37 | }; 38 | #endif // CONFIG_BT_ENABLED 39 | #endif /* COMPONENTS_CPP_UTILS_BLEVALUE_H_ */ 40 | -------------------------------------------------------------------------------- /cpp_utils/BLEXML/Characteristics/code/.gitignore: -------------------------------------------------------------------------------- 1 | *.xml 2 | *.json 3 | 4 | -------------------------------------------------------------------------------- /cpp_utils/BLEXML/Characteristics/code/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BASE_URL="https://www.bluetooth.com/api/gatt/XmlFile?xmlFileName=" 3 | RESULT=characteristics.json 4 | COUNT=0 5 | echo -e "[\n" > ${RESULT} 6 | for fileName in `cat characteristics.txt` 7 | do 8 | echo "Process file ${fileName}" 9 | wget --output-document ${fileName}.xml --quiet "${BASE_URL}${fileName}.xml" 10 | if [ ${COUNT} -gt 0 ] 11 | then 12 | echo -e ",\n" >> ${RESULT} 13 | fi 14 | #xml2json < "${fileName}.xml" >> ${RESULT} 15 | xml2json "${fileName}.xml" "${fileName}.json" 16 | cat "${fileName}.json" >> ${RESULT} 17 | COUNT=$(expr ${COUNT} + 1) 18 | done 19 | echo -e "\n]\n" >> ${RESULT} 20 | echo "done" 21 | -------------------------------------------------------------------------------- /cpp_utils/BLEXML/README.md: -------------------------------------------------------------------------------- 1 | # XML to JSON 2 | The BLE authority makes available description of Services and Characteristics in XML documents. Our goal is to work with these 3 | in JavaScript. These tools download each of the XML documents and convert them to JSON equivalents. To perform that task we 4 | use the NPM package called [xml2json-cli](https://www.npmjs.com/package/xml2json-cli). -------------------------------------------------------------------------------- /cpp_utils/BLEXML/Services/code/.gitignore: -------------------------------------------------------------------------------- 1 | *.xml 2 | *.json 3 | 4 | -------------------------------------------------------------------------------- /cpp_utils/BLEXML/Services/code/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BASE_URL="https://www.bluetooth.com/api/gatt/XmlFile?xmlFileName=" 3 | RESULT=services.json 4 | COUNT=0 5 | echo -e "[\n" > ${RESULT} 6 | for fileName in `cat services.txt` 7 | do 8 | echo "Process file ${fileName}" 9 | wget --output-document ${fileName}.xml --quiet "${BASE_URL}${fileName}.xml" 10 | if [ ${COUNT} -gt 0 ] 11 | then 12 | echo -e ",\n" >> ${RESULT} 13 | fi 14 | #xml2json < "${fileName}.xml" >> ${RESULT} 15 | xml2json "${fileName}.xml" "${fileName}.json" 16 | cat "${fileName}.json" >> ${RESULT} 17 | COUNT=$(expr ${COUNT} + 1) 18 | done 19 | echo -e "\n]\n" >> ${RESULT} 20 | echo "done" 21 | -------------------------------------------------------------------------------- /cpp_utils/BLEXML/Services/code/services.txt: -------------------------------------------------------------------------------- 1 | org.bluetooth.service.alert_notification 2 | org.bluetooth.service.automation_io 3 | org.bluetooth.service.battery_service 4 | org.bluetooth.service.blood_pressure 5 | org.bluetooth.service.body_composition 6 | org.bluetooth.service.bond_management 7 | org.bluetooth.service.continuous_glucose_monitoring 8 | org.bluetooth.service.current_time 9 | org.bluetooth.service.cycling_power 10 | org.bluetooth.service.cycling_speed_and_cadence 11 | org.bluetooth.service.device_information 12 | org.bluetooth.service.environmental_sensing 13 | org.bluetooth.service.fitness_machine 14 | org.bluetooth.service.generic_access 15 | org.bluetooth.service.generic_attribute 16 | org.bluetooth.service.glucose 17 | org.bluetooth.service.health_thermometer 18 | org.bluetooth.service.heart_rate 19 | org.bluetooth.service.http_proxy 20 | org.bluetooth.service.human_interface_device 21 | org.bluetooth.service.immediate_alert 22 | org.bluetooth.service.indoor_positioning 23 | org.bluetooth.service.internet_protocol_support 24 | org.bluetooth.service.link_loss 25 | org.bluetooth.service.location_and_navigation 26 | org.bluetooth.service.next_dst_change 27 | org.bluetooth.service.object_transfer 28 | org.bluetooth.service.phone_alert_status 29 | org.bluetooth.service.pulse_oximeter 30 | org.bluetooth.service.reference_time_update 31 | org.bluetooth.service.running_speed_and_cadence 32 | org.bluetooth.service.scan_parameters 33 | org.bluetooth.service.transport_discovery 34 | org.bluetooth.service.tx_power 35 | org.bluetooth.service.user_data 36 | org.bluetooth.service.weight_scale -------------------------------------------------------------------------------- /cpp_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Edit following two lines to set component requirements (see docs) 2 | set(COMPONENT_REQUIRES 3 | "console" 4 | "fatfs" 5 | "json" 6 | "mdns" 7 | "nvs_flash" 8 | ) 9 | set(COMPONENT_PRIV_REQUIRES ) 10 | 11 | file(GLOB COMPONENT_SRCS 12 | LIST_DIRECTORIES false 13 | "*.h" 14 | "*.cpp" 15 | "*.c" 16 | "*.S" 17 | ) 18 | set(COMPONENT_ADD_INCLUDEDIRS ".") 19 | 20 | register_component() 21 | -------------------------------------------------------------------------------- /cpp_utils/CPPNVS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NVS.h 3 | * 4 | * Created on: Mar 27, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_CPPNVS_H_ 9 | #define COMPONENTS_CPP_UTILS_CPPNVS_H_ 10 | #include 11 | #include 12 | 13 | /** 14 | * @brief Provide Non Volatile Storage access. 15 | */ 16 | class NVS { 17 | public: 18 | NVS(std::string name, nvs_open_mode openMode = NVS_READWRITE); 19 | virtual ~NVS(); 20 | void commit(); 21 | 22 | void erase(); 23 | void erase(std::string key); 24 | int get(std::string key, std::string* result, bool isBlob = false); 25 | int get(std::string key, uint8_t* result, size_t& length); 26 | int get(std::string key, uint32_t& value); 27 | void set(std::string key, std::string data, bool isBlob = false); 28 | void set(std::string key, uint32_t value); 29 | void set(std::string key, uint8_t* data, size_t length); 30 | 31 | private: 32 | std::string m_name; 33 | nvs_handle m_handle; 34 | 35 | }; 36 | 37 | #endif /* COMPONENTS_CPP_UTILS_CPPNVS_H_ */ 38 | -------------------------------------------------------------------------------- /cpp_utils/DesignNotes/README.md: -------------------------------------------------------------------------------- 1 | # Design Notes 2 | Here is where we keep some of our design documents. -------------------------------------------------------------------------------- /cpp_utils/FATFS_VFS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FATFS.h 3 | * 4 | * Created on: May 20, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_FATFS_VFS_H_ 9 | #define COMPONENTS_CPP_UTILS_FATFS_VFS_H_ 10 | #include 11 | extern "C" { 12 | #include 13 | #include 14 | } 15 | /** 16 | * @brief Provide access to the FAT file system on %SPI flash. 17 | * The FATFS_VFS file system needs a partition definition. This is a map of flash memory that 18 | * specified an array into which the files should be saved and loaded. A partition is a named 19 | * entity and the name we choose in the partition definition should be named in the constructor. 20 | * 21 | * A partition configuration file can be described in the `make menuconfig` settings. For example: 22 | * ~~~~ 23 | * nvs, data, nvs, 0x9000, 0x6000, 24 | * phy_init, data, phy, 0xf000, 0x1000, 25 | * factory, app, factory, 0x10000, 1M, 26 | * storage, data, fat, , 1M, 27 | * ~~~~ 28 | * 29 | * The recommended file name for the partition description is `partitions.csv` 30 | * 31 | * A typical example would be: 32 | * 33 | * @code{.cpp} 34 | * FATFS_VFS *fs = new FATFS_VFS("/spiflash", "storage"); 35 | * fs->mount(); 36 | * // Perform file I/O 37 | * fs->unmount(); 38 | * delete fs; 39 | * @endcode 40 | * 41 | */ 42 | class FATFS_VFS { 43 | public: 44 | FATFS_VFS(std::string mountPath, std::string partitionName); 45 | virtual ~FATFS_VFS(); 46 | 47 | void mount(); 48 | void setMaxFiles(int maxFiles); 49 | void unmount(); 50 | private: 51 | wl_handle_t m_wl_handle; 52 | std::string m_mountPath; 53 | std::string m_partitionName; 54 | int m_maxFiles; 55 | }; 56 | 57 | #endif /* COMPONENTS_CPP_UTILS_FATFS_VFS_H_ */ 58 | -------------------------------------------------------------------------------- /cpp_utils/File.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File.h 3 | * 4 | * Created on: Jun 1, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_FILE_H_ 9 | #define COMPONENTS_CPP_UTILS_FILE_H_ 10 | #include 11 | #include 12 | 13 | /** 14 | * @brief A logical representation of a file. 15 | */ 16 | class File { 17 | public: 18 | File(std::string name, uint8_t type = DT_UNKNOWN); 19 | 20 | std::string getContent(bool base64Encode = false); 21 | std::string getContent(uint32_t offset, uint32_t size); 22 | std::string getName(); 23 | std::string getPath(); 24 | uint8_t getType(); 25 | bool isDirectory(); 26 | uint32_t length(); 27 | 28 | private: 29 | std::string m_path; 30 | uint8_t m_type; 31 | }; 32 | 33 | #endif /* COMPONENTS_CPP_UTILS_FILE_H_ */ 34 | -------------------------------------------------------------------------------- /cpp_utils/FileSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FileSystem.h 3 | * 4 | * Created on: May 20, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_FILESYSTEM_H_ 9 | #define COMPONENTS_CPP_UTILS_FILESYSTEM_H_ 10 | #include 11 | #include 12 | #include 13 | /** 14 | * @brief File system utilities. 15 | */ 16 | class FileSystem { 17 | public: 18 | static std::vector getDirectoryContents(std:: string path); 19 | static void dumpDirectory(std::string path); 20 | static bool isDirectory(std::string path); 21 | static int mkdir(std::string path); 22 | static std::vector pathSplit(std::string path); 23 | static int remove(std::string path); 24 | }; 25 | 26 | #endif /* COMPONENTS_CPP_UTILS_FILESYSTEM_H_ */ 27 | -------------------------------------------------------------------------------- /cpp_utils/FreeRTOSTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOSTimer.h 3 | * 4 | * Created on: Mar 8, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_FREERTOSTIMER_H_ 9 | #define COMPONENTS_CPP_UTILS_FREERTOSTIMER_H_ 10 | #include 11 | #include 12 | #include 13 | /** 14 | * @brief Wrapper around the %FreeRTOS timer functions. 15 | */ 16 | class FreeRTOSTimer { 17 | public: 18 | FreeRTOSTimer(char* name, TickType_t period, UBaseType_t reload, void* data, void (*callback)(FreeRTOSTimer* pTimer)); 19 | virtual ~FreeRTOSTimer(); 20 | void changePeriod(TickType_t newPeriod, TickType_t blockTime = portMAX_DELAY); 21 | void* getData(); 22 | const char* getName(); 23 | TickType_t getPeriod(); 24 | void reset(TickType_t blockTime = portMAX_DELAY); 25 | void start(TickType_t blockTime = portMAX_DELAY); 26 | void stop(TickType_t blockTime = portMAX_DELAY); 27 | 28 | private: 29 | TimerHandle_t timerHandle; 30 | TickType_t period; 31 | void (*callback)(FreeRTOSTimer* pTimer); 32 | static void internalCallback(TimerHandle_t xTimer); 33 | 34 | }; 35 | 36 | #endif /* COMPONENTS_CPP_UTILS_FREERTOSTIMER_H_ */ 37 | -------------------------------------------------------------------------------- /cpp_utils/GPIO.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GPIO.h 3 | * 4 | * Created on: Feb 28, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_GPIO_H_ 9 | #define COMPONENTS_CPP_UTILS_GPIO_H_ 10 | #include 11 | namespace ESP32CPP { 12 | /** 13 | * @brief Interface to %GPIO functions. 14 | * 15 | * The %GPIO functions encapsulate the %GPIO access. The GPIOs available to us are 16 | * 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,25,26,27,32,33,34,35,36,37,38,39. 17 | * 18 | * The GPIOs of 34,35,36,37,38 and 39 are input only. 19 | * 20 | * Note that we must not use `int` values for the pin numbers but instead use the `gpio_num_t`. There 21 | * are constants defined for these of the form `GPIO_NUM_xx`. 22 | * 23 | * To toggle a pin we might code: 24 | * 25 | * @code{.cpp} 26 | * ESP32CPP::GPIO::setOutput(pin); 27 | * ESP32CPP::GPIO::high(pin); 28 | * ESP32CPP::GPIO::low(pin); 29 | * @endcode 30 | */ 31 | class GPIO { 32 | public: 33 | static void addISRHandler(gpio_num_t pin, gpio_isr_t handler, void* pArgs); 34 | static void high(gpio_num_t pin); 35 | static void interruptDisable(gpio_num_t pin); 36 | static void interruptEnable(gpio_num_t pin); 37 | static bool inRange(gpio_num_t pin); 38 | static void low(gpio_num_t pin); 39 | static bool read(gpio_num_t pin); 40 | static void setInput(gpio_num_t pin); 41 | static void setInterruptType(gpio_num_t pin, gpio_int_type_t intrType); 42 | static void setOutput(gpio_num_t pin); 43 | static void write(gpio_num_t pin, bool value); 44 | static void writeByte(gpio_num_t pins[], uint8_t value, int bits); 45 | }; // End GPIO 46 | } // End ESP32CPP namespace 47 | #endif /* COMPONENTS_CPP_UTILS_GPIO_H_ */ 48 | -------------------------------------------------------------------------------- /cpp_utils/GeneralUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GeneralUtils.h 3 | * 4 | * Created on: May 20, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_GENERALUTILS_H_ 9 | #define COMPONENTS_CPP_UTILS_GENERALUTILS_H_ 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /** 17 | * @brief General utilities. 18 | */ 19 | class GeneralUtils { 20 | public: 21 | static bool base64Decode(const std::string& in, std::string* out); 22 | static bool base64Encode(const std::string& in, std::string* out); 23 | static void dumpInfo(); 24 | static bool endsWith(std::string str, char c); 25 | static const char* errorToString(esp_err_t errCode); 26 | static const char* wifiErrorToString(uint8_t value); 27 | static void hexDump(const uint8_t* pData, uint32_t length); 28 | static std::string ipToString(uint8_t* ip); 29 | static std::vector split(std::string source, char delimiter); 30 | static std::string toLower(std::string& value); 31 | static std::string trim(const std::string& str); 32 | 33 | }; 34 | 35 | #endif /* COMPONENTS_CPP_UTILS_GENERALUTILS_H_ */ 36 | -------------------------------------------------------------------------------- /cpp_utils/HttpParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HttpParser.h 3 | * 4 | * Created on: Aug 28, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef CPP_UTILS_HTTPPARSER_H_ 9 | #define CPP_UTILS_HTTPPARSER_H_ 10 | #include 11 | #include 12 | #include "Socket.h" 13 | 14 | class HttpParser { 15 | public: 16 | HttpParser(); 17 | virtual ~HttpParser(); 18 | std::string getBody(); 19 | std::string getHeader(const std::string& name); 20 | std::map getHeaders(); 21 | std::string getMethod(); 22 | std::string getURL(); 23 | std::string getVersion(); 24 | std::string getStatus(); 25 | std::string getReason(); 26 | bool hasHeader(const std::string& name); 27 | void parse(std::string message); 28 | void parse(Socket s); 29 | void parseResponse(std::string message); 30 | 31 | private: 32 | std::string m_method; 33 | std::string m_url; 34 | std::string m_version; 35 | std::string m_body; 36 | std::string m_status; 37 | std::string m_reason; 38 | std::map m_headers; 39 | void dump(); 40 | void parseRequestLine(std::string& line); 41 | void parseStatusLine(std::string& line); 42 | 43 | }; 44 | 45 | #endif /* CPP_UTILS_HTTPPARSER_H_ */ 46 | -------------------------------------------------------------------------------- /cpp_utils/I2C.h: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C.h 3 | * 4 | * Created on: Feb 24, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_I2C_H_ 9 | #define MAIN_I2C_H_ 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | /** 17 | * @brief Interface to %I2C functions. 18 | */ 19 | class I2C { 20 | public: 21 | /** 22 | * @brief The default SDA pin. 23 | */ 24 | static const gpio_num_t DEFAULT_SDA_PIN = GPIO_NUM_25; 25 | 26 | /** 27 | * @brief The default Clock pin. 28 | */ 29 | static const gpio_num_t DEFAULT_CLK_PIN = GPIO_NUM_26; 30 | 31 | /** 32 | * @brief The default Clock speed. 33 | */ 34 | static const uint32_t DEFAULT_CLK_SPEED = 100000; 35 | 36 | I2C(); 37 | void beginTransaction(); 38 | void endTransaction(); 39 | uint8_t getAddress() const; 40 | void init(uint8_t address, gpio_num_t sdaPin = DEFAULT_SDA_PIN, gpio_num_t sclPin = DEFAULT_CLK_PIN, uint32_t clkSpeed = DEFAULT_CLK_SPEED, i2c_port_t portNum = I2C_NUM_0, bool pullup = true); 41 | void read(uint8_t* bytes, size_t length, bool ack = true); 42 | void read(uint8_t* byte, bool ack = true); 43 | void scan(); 44 | void setAddress(uint8_t address); 45 | void setDebug(bool enabled); 46 | bool slavePresent(uint8_t address); 47 | void start(); 48 | void stop(); 49 | void write(uint8_t byte, bool ack = true); 50 | void write(uint8_t* bytes, size_t length, bool ack = true); 51 | 52 | private: 53 | uint8_t m_address; 54 | i2c_cmd_handle_t m_cmd; 55 | bool m_directionKnown; 56 | gpio_num_t m_sdaPin; 57 | gpio_num_t m_sclPin; 58 | i2c_port_t m_portNum; 59 | 60 | }; 61 | 62 | #endif /* MAIN_I2C_H_ */ 63 | -------------------------------------------------------------------------------- /cpp_utils/IFTTT.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IFTTT.cpp 3 | * 4 | * Created on: Mar 14, 2017 5 | * Author: kolban 6 | */ 7 | #if defined(ESP_HAVE_CURL) 8 | #include "IFTTT.h" 9 | #include 10 | 11 | 12 | /** 13 | * @brief Construct an IFTTT maker client using the supplied key. 14 | */ 15 | IFTTT::IFTTT(std::string key) { 16 | m_key = key; 17 | m_restClient.addHeader("Content-Type", "application/json"); 18 | m_restClient.setVerbose(true); 19 | } // IFTTT 20 | 21 | 22 | IFTTT::~IFTTT() { 23 | } // ~IFTTT 24 | 25 | 26 | /** 27 | * @brief Trigger a maker event at IFTTT. 28 | * 29 | * @param [in] event The event type to send. 30 | * @param [in] value1 The value of value1. 31 | * @param [in] value2 The value of value2. 32 | * @param [in] value3 The value of value3. 33 | */ 34 | void IFTTT::trigger( 35 | std::string event, 36 | std::string value1, 37 | std::string value2, 38 | std::string value3) { 39 | m_restClient.setURL("https://maker.ifttt.com/trigger/" + event + "/with/key/" + m_key); 40 | cJSON* root; 41 | root = cJSON_CreateObject(); 42 | 43 | cJSON_AddStringToObject(root, "value1", value1.c_str()); 44 | cJSON_AddStringToObject(root, "value2", value2.c_str()); 45 | cJSON_AddStringToObject(root, "value3", value3.c_str()); 46 | 47 | m_restClient.post(std::string(cJSON_Print(root))); 48 | 49 | cJSON_Delete(root); 50 | } // trigger 51 | #endif // ESP_HAVE_CURL 52 | -------------------------------------------------------------------------------- /cpp_utils/IFTTT.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IFTTT.h 3 | * 4 | * Created on: Mar 14, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_IFTTT_H_ 9 | #define MAIN_IFTTT_H_ 10 | 11 | #include 12 | #include 13 | /** 14 | * @brief Encapsulate %IFTTT calls. 15 | */ 16 | class IFTTT { 17 | public: 18 | IFTTT(std::string key); 19 | virtual ~IFTTT(); 20 | void trigger(std::string event, std::string value1 = "", std::string value2 = "", std::string value3 = ""); 21 | private: 22 | RESTClient m_restClient; 23 | std::string m_key; 24 | }; 25 | 26 | #endif /* MAIN_IFTTT_H_ */ 27 | -------------------------------------------------------------------------------- /cpp_utils/Kconfig: -------------------------------------------------------------------------------- 1 | menu "C++ settings" 2 | 3 | config LIBCURL_PRESENT 4 | bool "LibCurl present" 5 | default false 6 | help 7 | Set to true to indicate that LibCurl is present. 8 | 9 | config U8G2_PRESENT 10 | bool "U8G2 present" 11 | default false 12 | help 13 | Set to true to indicate that U8G2 library is present. 14 | 15 | config MONGOOSE_PRESENT 16 | bool "Mongoose present" 17 | default false 18 | help 19 | Set to true to indicate that the Mongoose library is present. 20 | 21 | endmenu 22 | -------------------------------------------------------------------------------- /cpp_utils/MFRC522Debug.h: -------------------------------------------------------------------------------- 1 | #include "MFRC522.h" 2 | 3 | #ifndef MFRC522Debug_h 4 | #define MFRC522Debug_h 5 | 6 | class MFRC522Debug { 7 | public: 8 | // Get human readable code and type 9 | static const char* PICC_GetTypeName(MFRC522::PICC_Type type); 10 | static const char* GetStatusCodeName(MFRC522::StatusCode code); 11 | 12 | }; 13 | #endif // MFRC522Debug_h 14 | -------------------------------------------------------------------------------- /cpp_utils/MMU.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MMU.h 3 | * 4 | * Created on: Jun 30, 2018 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_MMU_H_ 9 | #define COMPONENTS_CPP_UTILS_MMU_H_ 10 | #include 11 | #include 12 | #include 13 | 14 | class MMU { 15 | public: 16 | MMU(); 17 | virtual ~MMU(); 18 | static void dump(); 19 | static void mapFlashToVMA(uint32_t flashOffset, void* vma, size_t size); 20 | }; 21 | 22 | #endif /* COMPONENTS_CPP_UTILS_MMU_H_ */ 23 | -------------------------------------------------------------------------------- /cpp_utils/Memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Memory.h 3 | * 4 | * Created on: Oct 24, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_MEMORY_H_ 9 | #define COMPONENTS_CPP_UTILS_MEMORY_H_ 10 | #include "sdkconfig.h" 11 | #ifdef CONFIG_HEAP_TRACING 12 | #include 13 | extern "C" { 14 | #include 15 | } 16 | 17 | class Memory { 18 | public: 19 | static bool checkIntegrity(); 20 | static void dump(); 21 | static void dumpRanges(); 22 | static void dumpHeapChange(std::string tag); 23 | static void init(uint32_t recordCount); 24 | static void resumeTrace(); 25 | static void startTraceAll(); 26 | static void startTraceLeaks(); 27 | static void stopTrace(); 28 | 29 | private: 30 | static heap_trace_record_t* m_pRecords; 31 | static size_t m_lastHeapSize; // Size of last heap recorded. 32 | }; 33 | #endif 34 | #endif /* COMPONENTS_CPP_UTILS_MEMORY_H_ */ 35 | -------------------------------------------------------------------------------- /cpp_utils/NeoPixelWiFiEventHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * NeoPixelWiFiEventHandler.cpp 3 | * 4 | * Created on: Mar 1, 2017 5 | * Author: kolban 6 | */ 7 | #include 8 | #include 9 | #include "NeoPixelWiFiEventHandler.h" 10 | 11 | static const char* LOG_TAG = "NeoPixelWiFiEventHandler"; 12 | 13 | NeoPixelWiFiEventHandler::NeoPixelWiFiEventHandler(gpio_num_t gpioPin) { 14 | this->gpioPin = gpioPin; 15 | ws2812 = new WS2812(gpioPin, 8); 16 | } 17 | 18 | NeoPixelWiFiEventHandler::~NeoPixelWiFiEventHandler() { 19 | delete ws2812; 20 | } 21 | 22 | esp_err_t NeoPixelWiFiEventHandler::apStart() { 23 | ESP_LOGD(LOG_TAG, "XXX apStart"); 24 | ws2812->setPixel(0, 0, 00, 64); 25 | ws2812->show(); 26 | return ESP_OK; 27 | } 28 | 29 | esp_err_t NeoPixelWiFiEventHandler::staConnected(system_event_sta_connected_t info) { 30 | ESP_LOGD(LOG_TAG, "XXX staConnected"); 31 | ws2812->setPixel(0, 57, 89, 66); 32 | ws2812->show(); 33 | return ESP_OK; 34 | } 35 | 36 | esp_err_t NeoPixelWiFiEventHandler::staDisconnected(system_event_sta_disconnected_t info) { 37 | ESP_LOGD(LOG_TAG, "XXX staDisconnected"); 38 | ws2812->setPixel(0, 64, 0, 0); 39 | ws2812->show(); 40 | return ESP_OK; 41 | } 42 | 43 | esp_err_t NeoPixelWiFiEventHandler::staStart() { 44 | ESP_LOGD(LOG_TAG, "XXX staStart"); 45 | ws2812->setPixel(0, 64, 64, 0); 46 | ws2812->show(); 47 | return ESP_OK; 48 | } 49 | 50 | esp_err_t NeoPixelWiFiEventHandler::staGotIp(system_event_sta_got_ip_t info) { 51 | ESP_LOGD(LOG_TAG, "XXX staGotIp"); 52 | ws2812->setPixel(0, 0, 64, 0); 53 | ws2812->show(); 54 | return ESP_OK; 55 | } 56 | 57 | esp_err_t NeoPixelWiFiEventHandler::wifiReady() { 58 | ESP_LOGD(LOG_TAG, "XXX wifiReady"); 59 | ws2812->setPixel(0, 64, 64, 0); 60 | ws2812->show(); 61 | return ESP_OK; 62 | } 63 | -------------------------------------------------------------------------------- /cpp_utils/NeoPixelWiFiEventHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NeoPixelWiFiEventHandler.h 3 | * 4 | * Created on: Mar 1, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_NEOPIXELWIFIEVENTHANDLER_H_ 9 | #define MAIN_NEOPIXELWIFIEVENTHANDLER_H_ 10 | #include "WiFiEventHandler.h" 11 | #include 12 | 13 | /** 14 | * @brief Color a neopixel as a function of the %WiFi state. 15 | * 16 | * When an ESP32 runs, we can't tell by looking at it the state of the %WiFi connection. 17 | * This class provides a %WiFi event handler that colors a NeoPixel as a function of the 18 | * state of the %WiFi. 19 | */ 20 | class NeoPixelWiFiEventHandler: public WiFiEventHandler { 21 | public: 22 | NeoPixelWiFiEventHandler(gpio_num_t gpioPin); 23 | virtual ~NeoPixelWiFiEventHandler(); 24 | 25 | esp_err_t apStart() override; 26 | esp_err_t staConnected(system_event_sta_connected_t info) override; 27 | esp_err_t staGotIp(system_event_sta_got_ip_t info) override; 28 | esp_err_t staDisconnected(system_event_sta_disconnected_t info) override; 29 | esp_err_t wifiReady() override; 30 | esp_err_t staStart() override; 31 | 32 | private: 33 | gpio_num_t gpioPin; 34 | WS2812* ws2812; 35 | }; 36 | 37 | #endif /* MAIN_NEOPIXELWIFIEVENTHANDLER_H_ */ 38 | -------------------------------------------------------------------------------- /cpp_utils/PCF8574.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PCF8574.h 3 | * 4 | * Created on: Mar 2, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_PCF8574_H_ 9 | #define COMPONENTS_CPP_UTILS_PCF8574_H_ 10 | #include "I2C.h" 11 | 12 | /** 13 | * @brief Encapsulate a %PCF8574 device. 14 | * 15 | * The %PCF8574 is a 8 bit %GPIO expander attached to %I2C. It can read and write 8 bits of data 16 | * and hence has 8 pins that can be used for input or output. 17 | * 18 | * @see [PCF8574 home page](http://www.ti.com/product/PCF8574) 19 | */ 20 | class PCF8574 { 21 | public: 22 | PCF8574(uint8_t address); 23 | virtual ~PCF8574(); 24 | void init(gpio_num_t sdaPin = I2C::DEFAULT_SDA_PIN, gpio_num_t clkPin = I2C::DEFAULT_CLK_PIN); 25 | uint8_t read(); 26 | bool readBit(uint8_t bit); 27 | void setInvert(bool value); 28 | void write(uint8_t value); 29 | void writeBit(uint8_t bit, bool value); 30 | 31 | private: 32 | I2C* i2c; 33 | uint8_t lastWrite; 34 | bool invert = false; 35 | 36 | }; 37 | 38 | #endif /* COMPONENTS_CPP_UTILS_PCF8574_H_ */ 39 | -------------------------------------------------------------------------------- /cpp_utils/PCF8575.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PCF8575.h 3 | * 4 | * Created on: Jan 27, 2018 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_PCF8575_H_ 9 | #define COMPONENTS_CPP_UTILS_PCF8575_H_ 10 | #include "I2C.h" 11 | 12 | /** 13 | * @brief Encapsulate a %PCF8575 device. 14 | * 15 | * The %PCF8575 is a 16 bit %GPIO expander attached to %I2C. It can read and write 16 bits of data 16 | * and hence has 16 pins that can be used for input or output. 17 | * 18 | * @see [PCF8575 home page](http://www.ti.com/product/PCF8575) 19 | */ 20 | class PCF8575 { 21 | public: 22 | PCF8575(uint8_t address); 23 | virtual ~PCF8575(); 24 | void init(gpio_num_t sdaPin = I2C::DEFAULT_SDA_PIN, gpio_num_t clkPin = I2C::DEFAULT_CLK_PIN); 25 | uint16_t read(); 26 | bool readBit(uint16_t bit); 27 | void setInvert(bool value); 28 | void write(uint16_t value); 29 | void writeBit(uint16_t bit, bool value); 30 | 31 | private: 32 | I2C* i2c; 33 | uint16_t m_lastWrite; 34 | bool invert = false; 35 | }; 36 | 37 | #endif /* COMPONENTS_CPP_UTILS_PCF8575_H_ */ 38 | -------------------------------------------------------------------------------- /cpp_utils/PWM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PWM.h 3 | * 4 | * Created on: Mar 9, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_PWM_H_ 9 | #define COMPONENTS_CPP_UTILS_PWM_H_ 10 | #include 11 | /** 12 | * @brief A wrapper for ESP32 %PWM control. 13 | * 14 | * Pulse Width Modulation (%PWM) is known as "LEDC" in the ESP32. It allows us to set a repeating 15 | * clock signal. There are two aspects to the signal called the frequency and duty cycle. The 16 | * frequency is how many times per second the signal repeats. The duty cycle is how much of a single 17 | * period the output signal is high compared to low. For example, a duty cycle of 0% means that the signal 18 | * is always low, while a duty cycle of 100% means the signal is always high. A duty cycle of 50% means 19 | * that the signal is high for 50% of the output and low for the remaining 50%. 20 | */ 21 | class PWM { 22 | public: 23 | PWM( 24 | int gpioNum, 25 | uint32_t frequency = 100, 26 | ledc_timer_bit_t bitSize = LEDC_TIMER_10_BIT, 27 | ledc_timer_t timer = LEDC_TIMER_0, 28 | ledc_channel_t channel = LEDC_CHANNEL_0); 29 | 30 | uint32_t getDuty(); 31 | uint32_t getFrequency(); 32 | void setDuty(uint32_t duty); 33 | void setDutyPercentage(uint8_t percent); 34 | void setFrequency(uint32_t freq); 35 | void stop(bool idleLevel = false); 36 | 37 | private: 38 | ledc_channel_t m_channel; 39 | ledc_timer_t m_timer; 40 | ledc_timer_bit_t m_dutyResolution; // Bit size of timer. 41 | 42 | }; 43 | 44 | #endif /* COMPONENTS_CPP_UTILS_PWM_H_ */ 45 | -------------------------------------------------------------------------------- /cpp_utils/RMT.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RMT.h 3 | * 4 | * Created on: Mar 1, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_RMT_H_ 9 | #define COMPONENTS_CPP_UTILS_RMT_H_ 10 | #include 11 | #include 12 | 13 | /** 14 | * @brief Drive the %RMT peripheral. 15 | */ 16 | class RMT { 17 | public: 18 | RMT(gpio_num_t pin, rmt_channel_t channel = RMT_CHANNEL_0); 19 | virtual ~RMT(); 20 | void add(bool level, uint32_t duration); 21 | void clear(); 22 | void rxStart(); 23 | void rxStop(); 24 | void txStart(); 25 | void txStop(); 26 | void write(); 27 | 28 | private: 29 | rmt_channel_t channel; 30 | std::vector items; 31 | int bitCount = 0; 32 | 33 | }; 34 | 35 | #endif /* COMPONENTS_CPP_UTILS_RMT_H_ */ 36 | -------------------------------------------------------------------------------- /cpp_utils/SOC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SOC.cpp 3 | * 4 | * Created on: May 16, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #include "SOC.h" 9 | #include 10 | extern "C" { 11 | #include 12 | } 13 | #include 14 | 15 | SOC::SOC() { 16 | } 17 | 18 | SOC::~SOC() { 19 | } 20 | 21 | /** 22 | * @brief Dump the status of the I2S peripheral. 23 | * @return N/A. 24 | */ 25 | void SOC::I2S::dump() { 26 | printf("I2S settings\n"); 27 | printf("I2S_CLKM_CONF_REG\n"); 28 | printf("-----------------\n"); 29 | printf("clkm_div_num: %d, clkm_div_b: %d, clkm_div_a: %d, clk_en: %d, clka_en: %d\n", 30 | I2S0.clkm_conf.clkm_div_num, 31 | I2S0.clkm_conf.clkm_div_b, 32 | I2S0.clkm_conf.clkm_div_a, 33 | I2S0.clkm_conf.clk_en, 34 | I2S0.clkm_conf.clka_en); 35 | uint32_t clockSpeed; 36 | if (I2S0.clkm_conf.clkm_div_a == 0) { 37 | clockSpeed = 160000000 / I2S0.clkm_conf.clkm_div_num; 38 | } else { 39 | clockSpeed = 160000000 / (I2S0.clkm_conf.clkm_div_num + I2S0.clkm_conf.clkm_div_b / I2S0.clkm_conf.clkm_div_a); 40 | } 41 | printf("Clock speed: %d\n", clockSpeed); 42 | printf("\n"); 43 | 44 | printf("I2S_CONF_REG\n"); 45 | printf("------------\n"); 46 | printf("tx_slave_mod: %s, rx_slave_mod: %s, rx_msb_right: %d, rx_right_first: %d\n", 47 | (I2S0.conf.tx_slave_mod == 0) ? "Master" : "Slave", 48 | (I2S0.conf.rx_slave_mod == 0) ? "Master" : "Slave", 49 | I2S0.conf.rx_msb_right, 50 | I2S0.conf.rx_right_first); 51 | printf("\n"); 52 | 53 | printf("I2S_CONF2_REG\n"); 54 | printf("-------------\n"); 55 | printf("camera_en: %d, lcd_en: %d, inter_valud_en: %d\n", 56 | I2S0.conf2.camera_en, 57 | I2S0.conf2.lcd_en, 58 | I2S0.conf2.inter_valid_en); 59 | printf("\n"); 60 | 61 | printf("I2S_CONF_CHAN_REG\n"); 62 | printf("-----------------\n"); 63 | printf("tx_chan_mod: %d, rx_chan_mod: %d\n", 64 | I2S0.conf_chan.tx_chan_mod, 65 | I2S0.conf_chan.rx_chan_mod); 66 | printf("\n"); 67 | } // I2S::dump 68 | -------------------------------------------------------------------------------- /cpp_utils/SOC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SOC.h 3 | * 4 | * Created on: May 16, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_SOC_H_ 9 | #define COMPONENTS_CPP_UTILS_SOC_H_ 10 | 11 | class SOC { 12 | public: 13 | SOC(); 14 | virtual ~SOC(); 15 | class I2S { 16 | public: 17 | static void dump(); 18 | }; 19 | }; 20 | 21 | #endif /* COMPONENTS_CPP_UTILS_SOC_H_ */ 22 | -------------------------------------------------------------------------------- /cpp_utils/SPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPI.h 3 | * 4 | * Created on: Mar 3, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_SPI_H_ 9 | #define COMPONENTS_CPP_UTILS_SPI_H_ 10 | #include 11 | #include 12 | /** 13 | * @brief Handle %SPI protocol. 14 | */ 15 | class SPI { 16 | public: 17 | SPI(); 18 | virtual ~SPI(); 19 | void init( 20 | int mosiPin = DEFAULT_MOSI_PIN, 21 | int misoPin = DEFAULT_MISO_PIN, 22 | int clkPin = DEFAULT_CLK_PIN, 23 | int csPin = DEFAULT_CS_PIN); 24 | void setHost(spi_host_device_t host); 25 | void transfer(uint8_t* data, size_t dataLen); 26 | uint8_t transferByte(uint8_t value); 27 | 28 | /** 29 | * @brief The default MOSI pin. 30 | */ 31 | static const int DEFAULT_MOSI_PIN = GPIO_NUM_13; 32 | 33 | /** 34 | * @brief The default MISO pin. 35 | */ 36 | static const int DEFAULT_MISO_PIN = GPIO_NUM_12; 37 | 38 | /** 39 | * @brief The default CLK pin. 40 | */ 41 | static const int DEFAULT_CLK_PIN = GPIO_NUM_14; 42 | 43 | /** 44 | * @brief The default CS pin. 45 | */ 46 | static const int DEFAULT_CS_PIN = GPIO_NUM_15; 47 | 48 | /** 49 | * @brief Value of unset pin. 50 | */ 51 | static const int PIN_NOT_SET = -1; 52 | 53 | private: 54 | spi_device_handle_t m_handle; 55 | spi_host_device_t m_host; 56 | 57 | }; 58 | 59 | #endif /* COMPONENTS_CPP_UTILS_SPI_H_ */ 60 | -------------------------------------------------------------------------------- /cpp_utils/SSLUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SSLUtils.cpp 3 | * 4 | * Created on: Sep 16, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #include "SSLUtils.h" 9 | #include 10 | #include 11 | 12 | char* SSLUtils::m_certificate = nullptr; 13 | char* SSLUtils::m_key = nullptr; 14 | 15 | SSLUtils::SSLUtils() { 16 | } 17 | 18 | SSLUtils::~SSLUtils() { 19 | } 20 | 21 | void SSLUtils::setCertificate(std::string certificate) { 22 | size_t len = certificate.length(); 23 | m_certificate = (char*) malloc(len + 1); 24 | memcpy(m_certificate, certificate.data(), len); 25 | m_certificate[len] = '\0'; 26 | } 27 | 28 | char* SSLUtils::getCertificate() { 29 | return m_certificate; 30 | } 31 | 32 | void SSLUtils::setKey(std::string key) { 33 | size_t len = key.length(); 34 | m_key = (char*) malloc(len + 1); 35 | memcpy(m_key, key.data(), len); 36 | m_key[len] = '\0'; 37 | } 38 | 39 | char* SSLUtils::getKey() { 40 | return m_key; 41 | } 42 | -------------------------------------------------------------------------------- /cpp_utils/SSLUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SSLUtils.h 3 | * 4 | * Created on: Sep 16, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_SSLUTILS_H_ 9 | #define COMPONENTS_CPP_UTILS_SSLUTILS_H_ 10 | #include 11 | class SSLUtils { 12 | private: 13 | static char* m_certificate; 14 | static char* m_key; 15 | public: 16 | SSLUtils(); 17 | virtual ~SSLUtils(); 18 | static void setCertificate(std::string certificate); 19 | static char* getCertificate(); 20 | static void setKey(std::string key); 21 | static char* getKey(); 22 | }; 23 | 24 | #endif /* COMPONENTS_CPP_UTILS_SSLUTILS_H_ */ 25 | -------------------------------------------------------------------------------- /cpp_utils/SmartLED.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SmartLED.h 3 | * 4 | * Created on: Oct 22, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_SMARTLED_H_ 9 | #define COMPONENTS_SMARTLED_H_ 10 | #include 11 | /** 12 | * @brief A data type representing the color of a pixel. 13 | */ 14 | typedef struct { 15 | /** 16 | * @brief The red component of the pixel. 17 | */ 18 | uint8_t red; 19 | /** 20 | * @brief The green component of the pixel. 21 | */ 22 | uint8_t green; 23 | /** 24 | * @brief The blue component of the pixel. 25 | */ 26 | uint8_t blue; 27 | } pixel_t; 28 | 29 | 30 | class SmartLED { 31 | public: 32 | SmartLED(); 33 | virtual ~SmartLED(); 34 | uint32_t getBrightness(); 35 | uint16_t getPixelCount(); 36 | virtual void init() = 0; 37 | virtual void show() = 0; 38 | void setBrightness(uint32_t percent); 39 | void setColorOrder(char* order); 40 | void setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue); 41 | void setPixel(uint16_t index, pixel_t pixel); 42 | void setPixel(uint16_t index, uint32_t pixel); 43 | void setPixelCount(uint16_t pixelCount); 44 | void setHSBPixel(uint16_t index, uint16_t hue, uint8_t saturation, uint8_t brightness); 45 | void clear(); 46 | 47 | protected: 48 | uint32_t m_brightness; 49 | char* m_colorOrder; 50 | uint16_t m_pixelCount; 51 | pixel_t* m_pixels; 52 | }; 53 | 54 | #endif /* COMPONENTS_SMARTLED_H_ */ 55 | -------------------------------------------------------------------------------- /cpp_utils/SockServ.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef MAIN_SOCKSERV_H_ 4 | #define MAIN_SOCKSERV_H_ 5 | #include 6 | #include 7 | #include 8 | #include "Socket.h" 9 | #include "FreeRTOS.h" 10 | #include 11 | #include 12 | 13 | 14 | /** 15 | * @brief Provide a socket listener and the ability to send data to connected partners. 16 | * 17 | * We use this class to listen on a given socket and accept connections from partners. 18 | * When we call one of the sendData() methods, the data passed as parameters is then sent 19 | * to the connected partners. 20 | * 21 | * Here is an example code fragment that uses the class: 22 | * 23 | * @code{.cpp} 24 | * SockServ mySockServer = SockServ(9876); 25 | * mySockServer.start(); 26 | * 27 | * // Later ... 28 | * mySockServer.sendData(data, dataLen); 29 | * @endcode 30 | * 31 | */ 32 | 33 | class SockServ { 34 | private: 35 | static void acceptTask(void*); 36 | uint16_t m_port; 37 | Socket m_serverSocket; 38 | FreeRTOS::Semaphore m_clientSemaphore = FreeRTOS::Semaphore("clientSemaphore"); 39 | std::set m_clientSet; 40 | QueueHandle_t m_acceptQueue; 41 | bool m_useSSL; 42 | 43 | public: 44 | SockServ(uint16_t port); 45 | SockServ(); 46 | ~SockServ(); 47 | int connectedCount(); 48 | void disconnect(Socket s); 49 | bool getSSL(); 50 | size_t receiveData(Socket s, void* pData, size_t maxData); 51 | void sendData(uint8_t* data, size_t length); 52 | void sendData(std::string str); 53 | void setPort(uint16_t port); 54 | void setSSL(bool use = true); 55 | void start(); 56 | void stop(); 57 | Socket waitForData(std::set& socketSet); 58 | Socket waitForNewClient(); 59 | 60 | }; 61 | 62 | #endif /* MAIN_SOCKSERV_H_ */ 63 | -------------------------------------------------------------------------------- /cpp_utils/System.h: -------------------------------------------------------------------------------- 1 | /* 2 | * System.h 3 | * 4 | * Created on: May 27, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_SYSTEM_H_ 9 | #define COMPONENTS_CPP_UTILS_SYSTEM_H_ 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * @brief System wide functions. 16 | */ 17 | class System { 18 | public: 19 | System(); 20 | virtual ~System(); 21 | static void dumpPinMapping(); // Dump the mappings of pins to functions. 22 | static void dumpHeapInfo(); 23 | static void getChipInfo(esp_chip_info_t* info); 24 | static size_t getFreeHeapSize(); 25 | static std::string getIDFVersion(); 26 | static size_t getMinimumFreeHeapSize(); 27 | static void restart(); 28 | }; 29 | 30 | #endif /* COMPONENTS_CPP_UTILS_SYSTEM_H_ */ 31 | -------------------------------------------------------------------------------- /cpp_utils/Task.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Task.h 3 | * 4 | * Created on: Mar 4, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_TASK_H_ 9 | #define COMPONENTS_CPP_UTILS_TASK_H_ 10 | #include 11 | #include 12 | #include 13 | /** 14 | * @brief Encapsulate a runnable task. 15 | * 16 | * This class is designed to be subclassed with the method: 17 | * 18 | * @code{.cpp} 19 | * void run(void *data) { ... } 20 | * @endcode 21 | * 22 | * For example: 23 | * 24 | * @code{.cpp} 25 | * class CurlTestTask : public Task { 26 | * void run(void *data) { 27 | * // Do something 28 | * } 29 | * }; 30 | * @endcode 31 | * 32 | * implemented. 33 | */ 34 | class Task { 35 | public: 36 | Task(std::string taskName = "Task", uint16_t stackSize = 10000, uint8_t priority = 5); 37 | virtual ~Task(); 38 | void setStackSize(uint16_t stackSize); 39 | void setPriority(uint8_t priority); 40 | void setName(std::string name); 41 | void setCore(BaseType_t coreId); 42 | void start(void* taskData = nullptr); 43 | void stop(); 44 | /** 45 | * @brief Body of the task to execute. 46 | * 47 | * This function must be implemented in the subclass that represents the actual task to run. 48 | * When a task is started by calling start(), this is the code that is executed in the 49 | * newly created task. 50 | * 51 | * @param [in] data The data passed in to the newly started task. 52 | */ 53 | virtual void run(void* data) = 0; // Make run pure virtual 54 | static void delay(int ms); 55 | 56 | private: 57 | xTaskHandle m_handle; 58 | void* m_taskData; 59 | static void runTask(void* data); 60 | std::string m_taskName; 61 | uint16_t m_stackSize; 62 | uint8_t m_priority; 63 | BaseType_t m_coreId; 64 | 65 | }; 66 | 67 | #endif /* COMPONENTS_CPP_UTILS_TASK_H_ */ 68 | -------------------------------------------------------------------------------- /cpp_utils/U8G2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * U8G2.cpp 3 | * 4 | * Created on: May 6, 2017 5 | * Author: kolban 6 | */ 7 | #include "sdkconfig.h" 8 | #ifdef CONFIG_U8G2_PRESENT 9 | #include "U8G2.h" 10 | #include 11 | extern "C" { 12 | #include 13 | } 14 | U8G2::U8G2(gpio_num_t sda, gpio_num_t scl, int address) { 15 | // TODO Auto-generated constructor stub 16 | u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT; 17 | u8g2_esp32_hal.sda = sda; 18 | u8g2_esp32_hal.scl = scl; 19 | u8g2_esp32_hal_init(u8g2_esp32_hal); 20 | 21 | u8g2_Setup_ssd1306_128x32_univision_f( 22 | &m_u8g2, 23 | U8G2_R0, 24 | //u8x8_byte_sw_i2c, 25 | u8g2_esp32_msg_i2c_cb, 26 | u8g2_esp32_msg_i2c_and_delay_cb); // init u8g2 structure 27 | u8x8_SetI2CAddress(&m_u8g2.u8x8,address << 1); 28 | } 29 | 30 | U8G2::~U8G2() { 31 | // TODO Auto-generated destructor stub 32 | } 33 | 34 | #endif // CONFIG_U8G2_PRESENT 35 | -------------------------------------------------------------------------------- /cpp_utils/WebSocketFileTransfer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WebSocketFileTransfer.h 3 | * 4 | * Created on: Sep 9, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_CPP_UTILS_WEBSOCKETFILETRANSFER_H_ 9 | #define COMPONENTS_CPP_UTILS_WEBSOCKETFILETRANSFER_H_ 10 | #include 11 | #include "WebSocket.h" 12 | 13 | class WebSocketFileTransfer { 14 | private: 15 | WebSocket* m_pWebSocket; // The WebSocket over which the file data will arrive. 16 | std::string m_rootPath; 17 | 18 | public: 19 | WebSocketFileTransfer(std::string rootPath); 20 | void start(WebSocket* pWebSocket); 21 | }; 22 | 23 | #endif /* COMPONENTS_CPP_UTILS_WEBSOCKETFILETRANSFER_H_ */ 24 | -------------------------------------------------------------------------------- /cpp_utils/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | COMPONENT_ADD_INCLUDEDIRS=. 9 | 10 | ## Uncomment the following line to enable exception handling 11 | #CXXFLAGS+=-fexceptions 12 | #CXXFLAGS+= -std=c++11 -------------------------------------------------------------------------------- /cpp_utils/library.properties: -------------------------------------------------------------------------------- 1 | name=ESP32 BLE Arduino 2 | version=0.1.0 3 | author=Neil Kolban 4 | maintainer=Neil Kolban 5 | sentence=BLE functions for ESP32 6 | paragraph=BLE functions for ESP32 7 | category=Communication 8 | url=https://github.com/nkolban/ESP32_BLE_Arduino 9 | architectures=esp32 10 | includes=BLE.h BLEUtils.h BLEScan.h BLEAdvertisedDevice.h 11 | dot_a_linkage=true -------------------------------------------------------------------------------- /cpp_utils/mainpage.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * @mainpage ESP32 C++ Utility Classes 3 | * The ESP-IDF is the C language based libraries and functions available for working with the ESP32 4 | * device. This ESP-IDF component provides a set of C++ classes that encapsulate and extend *some* of the 5 | * functions. 6 | * 7 | * The Github repository is [https://github.com/nkolban/esp32-snippets](https://github.com/nkolban/esp32-snippets). 8 | */ 9 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/Arduino/BLE_scan/BLE_scan.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp 3 | Ported to Arduino ESP32 by Evandro Copercini 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int scanTime = 30; //In seconds 12 | 13 | class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { 14 | void onResult(BLEAdvertisedDevice advertisedDevice) { 15 | Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); 16 | } 17 | }; 18 | 19 | void setup() { 20 | Serial.begin(115200); 21 | Serial.println("Scanning..."); 22 | 23 | BLEDevice::init(""); 24 | BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan 25 | pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); 26 | pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster 27 | BLEScanResults foundDevices = pBLEScan->start(scanTime); 28 | Serial.print("Devices found: "); 29 | Serial.println(foundDevices.getCount()); 30 | Serial.println("Scan done!"); 31 | } 32 | 33 | void loop() { 34 | // put your main code here, to run repeatedly: 35 | delay(2000); 36 | } -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/Arduino/BLE_server/BLE_server.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp 3 | Ported to Arduino ESP32 by Evandro Copercini 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // See the following for generating UUIDs: 11 | // https://www.uuidgenerator.net/ 12 | 13 | #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" 14 | #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" 15 | 16 | void setup() { 17 | Serial.begin(115200); 18 | Serial.println("Starting BLE work!"); 19 | 20 | BLEDevice::init("MyESP32"); 21 | BLEServer *pServer = BLEDevice::createServer(); 22 | BLEService *pService = pServer->createService(SERVICE_UUID); 23 | BLECharacteristic *pCharacteristic = pService->createCharacteristic( 24 | CHARACTERISTIC_UUID, 25 | BLECharacteristic::PROPERTY_READ | 26 | BLECharacteristic::PROPERTY_WRITE 27 | ); 28 | 29 | pCharacteristic->setValue("Hello World says Neil"); 30 | pService->start(); 31 | BLEAdvertising *pAdvertising = pServer->getAdvertising(); 32 | pAdvertising->addServiceUUID(SERVICE_UUID); 33 | pAdvertising->start(); 34 | Serial.println("Characteristic defined! Now you can read it in your phone!"); 35 | } 36 | 37 | void loop() { 38 | // put your main code here, to run repeatedly: 39 | delay(2000); 40 | } 41 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/Arduino/security/BLE_server/BLE_server_authorization/BLE_server_authorization.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp 3 | Ported to Arduino ESP32 by Evandro Copercini 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // See the following for generating UUIDs: 11 | // https://www.uuidgenerator.net/ 12 | 13 | #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" 14 | #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" 15 | 16 | void setup() { 17 | Serial.begin(115200); 18 | Serial.println("Starting BLE work!"); 19 | 20 | BLEDevice::init("ESP32"); 21 | BLEServer *pServer = BLEDevice::createServer(); 22 | BLEService *pService = pServer->createService(SERVICE_UUID); 23 | BLECharacteristic *pCharacteristic = pService->createCharacteristic( 24 | CHARACTERISTIC_UUID, 25 | BLECharacteristic::PROPERTY_READ | 26 | BLECharacteristic::PROPERTY_WRITE 27 | ); 28 | 29 | /* 30 | * Authorized permission to read/write characteristic. Require also protecting descriptor 2902 to protect notify/indicate requests 31 | */ 32 | 33 | pCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); 34 | pCharacteristic->setValue("Hello World says Neil"); 35 | pService->start(); 36 | BLEAdvertising *pAdvertising = pServer->getAdvertising(); 37 | pAdvertising->start(); 38 | Serial.println("Characteristic defined! Now you can read it in your phone!"); 39 | } 40 | 41 | void loop() { 42 | // put your main code here, to run repeatedly: 43 | delay(2000); 44 | } 45 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/Arduino/security/BLE_server/BLE_server_encrypted/BLE_server_encrypted.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp 3 | Ported to Arduino ESP32 by Evandro Copercini 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // See the following for generating UUIDs: 11 | // https://www.uuidgenerator.net/ 12 | 13 | #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" 14 | #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" 15 | 16 | void setup() { 17 | Serial.begin(115200); 18 | Serial.println("Starting BLE work!"); 19 | 20 | BLEDevice::init("ESP32"); 21 | /* 22 | * Here we have implemented simplest security. This kind security does not provide authentication 23 | */ 24 | BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT); 25 | BLEServer *pServer = BLEDevice::createServer(); 26 | BLEService *pService = pServer->createService(SERVICE_UUID); 27 | BLECharacteristic *pCharacteristic = pService->createCharacteristic( 28 | CHARACTERISTIC_UUID, 29 | BLECharacteristic::PROPERTY_READ | 30 | BLECharacteristic::PROPERTY_WRITE 31 | ); 32 | 33 | pCharacteristic->setValue("Hello World says Neil"); 34 | pService->start(); 35 | BLEAdvertising *pAdvertising = pServer->getAdvertising(); 36 | pAdvertising->start(); 37 | Serial.println("Characteristic defined! Now you can read it in your phone!"); 38 | } 39 | 40 | void loop() { 41 | // put your main code here, to run repeatedly: 42 | delay(2000); 43 | } 44 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/Arduino/security/StaticPIN/StaticPIN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp 3 | Ported to Arduino ESP32 by Evandro Copercini 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // See the following for generating UUIDs: 11 | // https://www.uuidgenerator.net/ 12 | 13 | #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" 14 | #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" 15 | 16 | void setup() { 17 | Serial.begin(115200); 18 | Serial.println("Starting BLE work!"); 19 | 20 | BLEDevice::init("ESP32"); 21 | /* 22 | * Required in authentication process to provide displaying and/or input passkey or yes/no butttons confirmation 23 | */ 24 | BLEServer *pServer = BLEDevice::createServer(); 25 | BLEService *pService = pServer->createService(SERVICE_UUID); 26 | BLECharacteristic *pCharacteristic = pService->createCharacteristic( 27 | CHARACTERISTIC_UUID, 28 | BLECharacteristic::PROPERTY_READ | 29 | BLECharacteristic::PROPERTY_WRITE 30 | ); 31 | pCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED); 32 | pCharacteristic->setValue("Hello World says Neil"); 33 | pService->start(); 34 | BLEAdvertising *pAdvertising = pServer->getAdvertising(); 35 | pAdvertising->start(); 36 | 37 | BLESecurity *pSecurity = new BLESecurity(); 38 | pSecurity->setStaticPIN(123456); 39 | 40 | //set static passkey 41 | Serial.println("Characteristic defined! Now you can read it in your phone!"); 42 | } 43 | 44 | void loop() { 45 | // put your main code here, to run repeatedly: 46 | delay(2000); 47 | } 48 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/README.md: -------------------------------------------------------------------------------- 1 | # Sample C++ BLE fragments 2 | Here we find a set of C++ BLE samples illustrating different aspects of the C++ BLE library. -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/SampleAsyncScan.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Perform an async scanning for BLE advertised servers. 3 | */ 4 | #include "BLEUtils.h" 5 | #include "BLEScan.h" 6 | #include 7 | 8 | #include "BLEDevice.h" 9 | #include "BLEAdvertisedDevice.h" 10 | #include "sdkconfig.h" 11 | 12 | /** 13 | * Callback for each detected advertised device. 14 | */ 15 | class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { 16 | void onResult(BLEAdvertisedDevice advertisedDevice) { 17 | printf("Advertised Device: %s\n", advertisedDevice.toString().c_str()); 18 | } 19 | }; 20 | 21 | 22 | /** 23 | * Callback invoked when scanning has completed. 24 | */ 25 | static void scanCompleteCB(BLEScanResults scanResults) { 26 | printf("Scan complete!\n"); 27 | printf("We found %d devices\n", scanResults.getCount()); 28 | scanResults.dump(); 29 | } // scanCompleteCB 30 | 31 | /** 32 | * Run the sample. 33 | */ 34 | static void run() { 35 | printf("Async Scanning sample starting\n"); 36 | BLEDevice::init(""); 37 | 38 | BLEScan* pBLEScan = BLEDevice::getScan(); 39 | pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), false); 40 | pBLEScan->setActiveScan(true); 41 | printf("About to start scanning for 10 seconds\n"); 42 | pBLEScan->start(10, scanCompleteCB); 43 | printf("Now scanning in the background ... scanCompleteCB() will be called when done.\n"); 44 | 45 | // 46 | // Now going into a loop logging that we are still alive. 47 | // 48 | while(1) { 49 | printf("Tick! - still alive\n"); 50 | FreeRTOS::sleep(1000); 51 | } 52 | printf("Scanning sample ended\n"); 53 | } 54 | 55 | void SampleAsyncScan(void) 56 | { 57 | run(); 58 | } // app_main 59 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/SampleScan.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Perform scanning for BLE advertised servers. 3 | */ 4 | #include "BLEUtils.h" 5 | #include "BLEScan.h" 6 | #include 7 | #include 8 | 9 | #include "BLEDevice.h" 10 | #include "BLEAdvertisedDevice.h" 11 | #include "sdkconfig.h" 12 | 13 | static const char LOG_TAG[] = "SampleScan"; 14 | 15 | class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { 16 | void onResult(BLEAdvertisedDevice advertisedDevice) { 17 | ESP_LOGD(LOG_TAG, "Advertised Device: %s", advertisedDevice.toString().c_str()); 18 | } 19 | }; 20 | 21 | static void run() { 22 | ESP_LOGD(LOG_TAG, "Scanning sample starting"); 23 | BLEDevice::init(""); 24 | BLEScan* pBLEScan = BLEDevice::getScan(); 25 | pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); 26 | pBLEScan->setActiveScan(true); 27 | BLEScanResults scanResults = pBLEScan->start(30); 28 | ESP_LOGD(LOG_TAG, "We found %d devices", scanResults.getCount()); 29 | ESP_LOGD(LOG_TAG, "Scanning sample ended"); 30 | } 31 | 32 | void SampleScan(void) 33 | { 34 | run(); 35 | } // app_main 36 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/SampleServer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Create a new BLE server. 3 | */ 4 | #include "BLEDevice.h" 5 | #include "BLEServer.h" 6 | #include "BLEUtils.h" 7 | #include "BLE2902.h" 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | #include "sdkconfig.h" 14 | 15 | static char LOG_TAG[] = "SampleServer"; 16 | 17 | class MainBLEServer: public Task { 18 | void run(void *data) { 19 | ESP_LOGD(LOG_TAG, "Starting BLE work!"); 20 | 21 | BLEDevice::init("ESP32"); 22 | BLEServer* pServer = BLEDevice::createServer(); 23 | 24 | BLEService* pService = pServer->createService("91bad492-b950-4226-aa2b-4ede9fa42f59"); 25 | 26 | BLECharacteristic* pCharacteristic = pService->createCharacteristic( 27 | BLEUUID("0d563a58-196a-48ce-ace2-dfec78acc814"), 28 | BLECharacteristic::PROPERTY_BROADCAST | BLECharacteristic::PROPERTY_READ | 29 | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_WRITE | 30 | BLECharacteristic::PROPERTY_INDICATE 31 | ); 32 | 33 | pCharacteristic->setValue("Hello World!"); 34 | 35 | BLE2902* p2902Descriptor = new BLE2902(); 36 | p2902Descriptor->setNotifications(true); 37 | pCharacteristic->addDescriptor(p2902Descriptor); 38 | 39 | pService->start(); 40 | 41 | BLEAdvertising* pAdvertising = pServer->getAdvertising(); 42 | pAdvertising->addServiceUUID(BLEUUID(pService->getUUID())); 43 | pAdvertising->start(); 44 | 45 | ESP_LOGD(LOG_TAG, "Advertising started!"); 46 | delay(1000000); 47 | } 48 | }; 49 | 50 | 51 | void SampleServer(void) 52 | { 53 | //esp_log_level_set("*", ESP_LOG_DEBUG); 54 | MainBLEServer* pMainBleServer = new MainBLEServer(); 55 | pMainBleServer->setStackSize(20000); 56 | pMainBleServer->start(); 57 | 58 | } // app_main 59 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Main file for running the BLE samples. 3 | */ 4 | extern "C" { 5 | void app_main(void); 6 | } 7 | 8 | 9 | // The list of sample entry points. 10 | void Sample_MLE_15(void); 11 | void Sample1(void); 12 | void SampleAsyncScan(void); 13 | void SampleClient(void); 14 | void SampleClient_Notify(void); 15 | void SampleClientAndServer(void); 16 | void SampleClientDisconnect(void); 17 | void SampleClientWithWiFi(void); 18 | void SampleNotify(void); 19 | void SampleRead(void); 20 | void SampleScan(void); 21 | void SampleSensorTag(void); 22 | void SampleServer(void); 23 | void SampleWrite(void); 24 | 25 | // 26 | // Un-comment ONE of the following 27 | // --- 28 | void app_main(void) { 29 | //Sample_MLE_15(); 30 | //Sample1(); 31 | //SampleAsyncScan(); 32 | //SampleClient(); 33 | //SampleClient_Notify(); 34 | //SampleClientAndServer(); 35 | //SampleClientDisconnect(); 36 | //SampleClientWithWiFi(); 37 | //SampleNotify(); 38 | //SampleRead(); 39 | //SampleSensorTag(); 40 | //SampleScan(); 41 | SampleServer(); 42 | //SampleWrite(); 43 | } // app_main 44 | -------------------------------------------------------------------------------- /cpp_utils/tests/BLETests/security/app_main_security.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Main file for running the BLE samples. 3 | */ 4 | extern "C" { 5 | void app_main(void); 6 | } 7 | 8 | 9 | // The list of sample entry points. 10 | 11 | void SampleClient_Encryption(void); 12 | void SampleServer_Encryption(void); 13 | void SampleClient_authentication_passkey(void); 14 | void SampleServer_authentication_passkey(void); 15 | void SampleClient_authentication_numeric_confirmation(void); 16 | void SampleServer_authentication_numeric_confirmation(void); 17 | 18 | void SampleServer_Authorization(void); 19 | 20 | // 21 | // Un-comment ONE of the following 22 | // --- 23 | void app_main(void) { 24 | 25 | SampleClient_Encryption(); 26 | // SampleServer_Encryption(); 27 | // SampleClient_authentication_passkey(); 28 | // SampleServer_authentication_passkey(); 29 | // SampleClient_authentication_numeric_confirmation(); 30 | // SampleServer_authentication_numeric_confirmation(); 31 | // 32 | // SampleServer_Authorization(); 33 | } // app_main 34 | -------------------------------------------------------------------------------- /cpp_utils/tests/MFRC522/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | extern void dumpInfo(); 4 | 5 | 6 | extern "C" { 7 | void app_main(); 8 | } 9 | 10 | class MyTask: public Task { 11 | void run(void* data) { 12 | int count = 0; 13 | /* 14 | while(1) { 15 | printf("count: %d\n", count); 16 | count++; 17 | vTaskDelay(1000/portTICK_PERIOD_MS); 18 | } 19 | */ 20 | /* 21 | char* x = "hello"; 22 | uint32_t i = 0; 23 | printf("Hello world!"); 24 | printf("Hello world! again!"); 25 | char* p = (char*) i; 26 | *p = 123; 27 | *p */ 28 | dumpInfo(); 29 | printf("Done\n"); 30 | } 31 | }; 32 | 33 | void app_main() { 34 | MyTask* pMyTask = new MyTask(); 35 | pMyTask->setStackSize(20000); 36 | pMyTask->start(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /cpp_utils/tests/task_i2c_scanner.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sdkconfig.h" 8 | 9 | #define DEVICE_ADDRESS 0 10 | #define SDA_PIN 25 11 | #define SCL_PIN 26 12 | 13 | //static char tag[] = "task_cpp_utils"; 14 | 15 | class I2CScanner: public Task { 16 | void run(void *data) override { 17 | I2C i2c; 18 | i2c.init((uint8_t)DEVICE_ADDRESS, (gpio_num_t)SDA_PIN, (gpio_num_t)SCL_PIN); 19 | i2c.scan(); 20 | } // End run 21 | }; 22 | 23 | 24 | static I2CScanner i2cScanner = I2CScanner(); 25 | 26 | void task_i2c_scanner(void *ignore) { 27 | i2cScanner.start(); 28 | FreeRTOS::deleteTask(); 29 | } 30 | -------------------------------------------------------------------------------- /cpp_utils/tests/task_mdns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "sdkconfig.h" 10 | 11 | static char tag[] = "task_mdns"; 12 | 13 | class TargetWiFiEventHandler: public WiFiEventHandler { 14 | esp_err_t staGotIp(system_event_sta_got_ip_t event_sta_got_ip) { 15 | ESP_LOGD(tag, "MyWiFiEventHandler(Class): staGotIp"); 16 | MDNS *mdns = new MDNS(); 17 | mdns->setHostname("HHHH"); 18 | mdns->setInstance("IIII"); 19 | mdns->serviceAdd("_test", "_tcp", 80); 20 | return ESP_OK; 21 | } 22 | }; 23 | 24 | class MDNSTask: public Task { 25 | void run(void *data) override { 26 | 27 | WiFi wifi; 28 | TargetWiFiEventHandler *eventHandler = new TargetWiFiEventHandler(); 29 | wifi.setWifiEventHandler(eventHandler); 30 | wifi.connectAP("sweetie", "l16wint!"); 31 | } // End run 32 | }; 33 | 34 | 35 | static MDNSTask myTask = MDNSTask(); 36 | 37 | void task_mdns(void *ignore) { 38 | myTask.setStackSize(8000); 39 | myTask.start(); 40 | FreeRTOS::deleteTask(); 41 | } 42 | -------------------------------------------------------------------------------- /cpp_utils/tests/test_max7219.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "MAX7219.h" 8 | 9 | #include "sdkconfig.h" 10 | 11 | //static char tag[] = "task_cpp_utils"; 12 | 13 | 14 | 15 | class TestMAX7219: public Task { 16 | void test8x8(MAX7219 &max7219) { 17 | int dir=1; 18 | int y=0; 19 | while(1) { 20 | for (auto x=0; x<8; x++) { 21 | for (auto i=0; i<8; i++) { 22 | max7219.setLed(x, y, true); 23 | FreeRTOS::sleep(100); 24 | max7219.setLed(x, y, false); 25 | y=y+dir; 26 | } 27 | dir = -dir; 28 | y=y+dir; 29 | } 30 | } 31 | } 32 | 33 | void test7SegDisplay(MAX7219 &max7219) { 34 | int i=0; 35 | while(1) { 36 | max7219.setNumber(i); 37 | i++; 38 | FreeRTOS::sleep(100); 39 | } 40 | } 41 | 42 | void run(void *data) override { 43 | SPI spi; 44 | spi.init(); 45 | 46 | MAX7219 max7219 = MAX7219(&spi, 1); 47 | max7219.shutdown(false); 48 | max7219.setIntensity(4); 49 | //test7SegDisplay(max7219); 50 | test8x8(max7219); 51 | 52 | } // End run 53 | }; 54 | 55 | 56 | static TestMAX7219 testMAX7219 = TestMAX7219(); 57 | 58 | void task_max7219(void *ignore) { 59 | testMAX7219.start(); 60 | FreeRTOS::deleteTask(); 61 | } 62 | -------------------------------------------------------------------------------- /cpp_utils/tests/test_rest_ifttt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Test the REST API client. 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "sdkconfig.h" 14 | 15 | static char tag[] = "test_rest"; 16 | 17 | extern "C" { 18 | void app_main(void); 19 | } 20 | 21 | 22 | static WiFi *wifi; 23 | 24 | class IFTTTTestTask: public Task { 25 | void run(void *data) { 26 | IFTTT iftt = IFTTT("dG-QmEUwCUyBBLHm1owPtq"); 27 | iftt.trigger("test", "A", "BCD", "Val3"); 28 | ESP_LOGD(tag, "trigger done!"); 29 | } 30 | }; 31 | 32 | 33 | class MyWiFiEventHandler: public WiFiEventHandler { 34 | 35 | esp_err_t staGotIp(system_event_sta_got_ip_t event_sta_got_ip) { 36 | ESP_LOGD(tag, "MyWiFiEventHandler(Class): staGotIp"); 37 | 38 | 39 | IFTTTTestTask *pTestTask= new IFTTTTestTask(); 40 | pTestTask->setStackSize(12000); 41 | pTestTask->start(); 42 | return ESP_OK; 43 | } 44 | }; 45 | 46 | 47 | void app_main(void) { 48 | ESP_LOGD(tag, "app_main: libcurl starting"); 49 | MyWiFiEventHandler *eventHandler = new MyWiFiEventHandler(); 50 | 51 | wifi = new WiFi(); 52 | wifi->setWifiEventHandler(eventHandler); 53 | 54 | wifi->connectAP("sweetie", "l16wint!"); 55 | } 56 | -------------------------------------------------------------------------------- /curl/README.md: -------------------------------------------------------------------------------- 1 | ## Missing Posix functions 2 | LibCurl is a moving target and on occassion, is updated to utilize functions that are not part of the ESP-IDF. For example, at the time of writing, the latest version of LibCurl uses the Posix `access(2)` system call that it previously did not. This call is not present in ESP-IDF. To circumvent the problem, a shim file has been provided in `./posix/posix_shims.c` that provides simple implementations for some missing Posix functions. -------------------------------------------------------------------------------- /curl/build_files/README.md: -------------------------------------------------------------------------------- 1 | # Building curl 2 | 3 | Create folder called `components` to host curl as a component. In the `components` folder run: 4 | 5 | ``` 6 | $ git clone https://github.com/curl/curl.git 7 | ``` 8 | 9 | This results in a download/clone of the `curl` library. A new folder called `curl` will be found. Go into that folder. 10 | 11 | We now need to copy some ESP32 specific configuration files. These are: 12 | 13 | * `lib/curl_config.h` 14 | * `component.mk` 15 | 16 | 17 | 18 | Once the above steps have been completed, we should be able to build our ESP-IDF project as normal and that will include the construction of the curl library ready for use. Now you can code directly to the curl APIs or you can code to the C++ REST classes that leverage curl. -------------------------------------------------------------------------------- /curl/build_files/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_SRCDIRS:=lib lib/vauth lib/vtls 2 | COMPONENT_PRIV_INCLUDEDIRS:=lib include 3 | CFLAGS+=-DHAVE_CONFIG_H -DBUILDING_LIBCURL 4 | -------------------------------------------------------------------------------- /filesystems/espfs/README.md: -------------------------------------------------------------------------------- 1 | #The ESP FS 2 | A fantastic project by Mr SpriteTM can be found here: 3 | 4 | [https://github.com/Spritetm/libesphttpd/tree/master/espfs](https://github.com/Spritetm/libesphttpd/tree/master/espfs) 5 | 6 | This provides an ESP File System that is read only and stored on flash. 7 | 8 | Here, you will find a copy of those core files that have been massaged to utilize ESP32 technologies. 9 | Primarily, we use flash memory mapping to access the data as opposed to individual flash reads. In addition, 10 | and the primary intent, a new method was added with the signature: 11 | 12 | ``` 13 | int espFsAccess(EspFsFile *fh, void **buf, size_t *len) 14 | ``` 15 | 16 | This function returns a pointer to the whole content of the file which is stored in buf. The 17 | length of the file is stored in len and also returned from the function as a whole. 18 | The data is accessed directly from flash without any RAM copies. 19 | In addition, the function called: 20 | 21 | ``` 22 | EspFsInitResult espFsInit(void *flashAddress, size_t size) 23 | ``` 24 | 25 | was augmented to include the size of the flash storage to map. 26 | 27 | For full details and background, see the following thread on the ESP32 forum: 28 | 29 | [http://esp32.com/viewtopic.php?f=13&t=698](http://esp32.com/viewtopic.php?f=13&t=698) -------------------------------------------------------------------------------- /filesystems/espfs/components/espfs/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. -------------------------------------------------------------------------------- /filesystems/espfs/components/espfs/espfs.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPFS_H 2 | #define ESPFS_H 3 | #include 4 | // This define is done in Makefile. If you do not use default Makefile, uncomment 5 | // to be able to use Heatshrink-compressed espfs images. 6 | //#define ESPFS_HEATSHRINK 7 | 8 | typedef enum { 9 | ESPFS_INIT_RESULT_OK, 10 | ESPFS_INIT_RESULT_NO_IMAGE, 11 | ESPFS_INIT_RESULT_BAD_ALIGN 12 | } EspFsInitResult; 13 | 14 | typedef struct EspFsFile EspFsFile; 15 | 16 | EspFsInitResult espFsInit(void *flashAddress, size_t size); 17 | EspFsFile *espFsOpen(char *fileName); 18 | int espFsFlags(EspFsFile *fh); 19 | int espFsRead(EspFsFile *fh, char *buff, int len); 20 | void espFsClose(EspFsFile *fh); 21 | int espFsAccess(EspFsFile *fh, void **buf, size_t *len); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /filesystems/espfs/components/espfs/espfsformat.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPROFSFORMAT_H 2 | #define ESPROFSFORMAT_H 3 | 4 | /* 5 | Stupid cpio-like tool to make read-only 'filesystems' that live on the flash SPI chip of the module. 6 | Can (will) use lzf compression (when I come around to it) to make shit quicker. Aligns names, files, 7 | headers on 4-byte boundaries so the SPI abstraction hardware in the ESP8266 doesn't crap on itself 8 | when trying to do a <4byte or unaligned read. 9 | */ 10 | 11 | /* 12 | The idea 'borrows' from cpio: it's basically a concatenation of {header, filename, file} data. 13 | Header, filename and file data is 32-bit aligned. The last file is indicated by data-less header 14 | with the FLAG_LASTFILE flag set. 15 | */ 16 | 17 | 18 | #define FLAG_LASTFILE (1<<0) 19 | #define FLAG_GZIP (1<<1) 20 | #define COMPRESS_NONE 0 21 | #define COMPRESS_HEATSHRINK 1 22 | #define ESPFS_MAGIC 0x73665345 23 | 24 | typedef struct { 25 | int32_t magic; 26 | int8_t flags; 27 | int8_t compression; 28 | int16_t nameLen; 29 | int32_t fileLenComp; 30 | int32_t fileLenDecomp; 31 | } __attribute__((packed)) EspFsHeader; 32 | 33 | #endif -------------------------------------------------------------------------------- /filesystems/espfs/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "sdkconfig.h" 7 | 8 | char tag[] = "espfs_main"; 9 | static void * flashAddress = (void *)(4*1024*1024 - 10 *64*1024); // 0x36 0000 10 | 11 | void doWork(void *ignore) { 12 | 13 | char buff[5*1024]; 14 | ESP_LOGD(tag, "Flash address is 0x%x", (int)flashAddress); 15 | if (espFsInit(flashAddress, 64*1024) != ESPFS_INIT_RESULT_OK) { 16 | ESP_LOGD(tag, "Failed to initialize espfs"); 17 | return; 18 | } 19 | 20 | EspFsFile *fh = espFsOpen("files/test3.txt");; 21 | 22 | if (fh != NULL) { 23 | int sizeRead = 0; 24 | sizeRead = espFsRead(fh, buff, sizeof(buff)); 25 | ESP_LOGD(tag, "Result: %.*s", sizeRead, buff); 26 | 27 | size_t fileSize; 28 | char *data; 29 | sizeRead = espFsAccess(fh, (void **)&data, &fileSize); 30 | ESP_LOGD(tag, "Result from access: %.*s", fileSize, data); 31 | 32 | espFsClose(fh); 33 | vTaskDelete(NULL); 34 | } 35 | } 36 | void app_main(void) 37 | { 38 | xTaskCreatePinnedToCore(&doWork, "doWork", 8000, NULL, 5, NULL, 0); 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /filesystems/sendZip/.gitignore: -------------------------------------------------------------------------------- 1 | /package-lock.json 2 | /node_modules/ 3 | -------------------------------------------------------------------------------- /filesystems/sendZip/test.js: -------------------------------------------------------------------------------- 1 | // https://www.npmjs.com/package/adm-zip 2 | // https://nodejs.org/api/stream.html 3 | // https://nodejs.org/api/net.html 4 | 5 | var AdmZip = require("adm-zip"); 6 | const net = require("net"); 7 | 8 | 9 | const lenBuf = Buffer.allocUnsafe(4); 10 | 11 | 12 | const client = net.createConnection({host: "192.168.1.99", port: 9876}, ()=>{ 13 | console.log("Connected!"); 14 | var zip = new AdmZip("./foo.zip"); 15 | var zipEntries = zip.getEntries(); 16 | zipEntries.forEach(zipEntry=>{ 17 | console.log("Entry: " + zipEntry.entryName); 18 | lenBuf.writeUInt32LE(zipEntry.entryName.length, 0); 19 | client.write(lenBuf); 20 | client.write(zipEntry.entryName); 21 | }); 22 | 23 | client.end(); 24 | }); -------------------------------------------------------------------------------- /filesystems/sendZip/ws_send_zip.js: -------------------------------------------------------------------------------- 1 | // https://www.npmjs.com/package/adm-zip 2 | // https://nodejs.org/api/stream.html 3 | // https://nodejs.org/api/net.html 4 | //API docs ...https://github.com/websockets/ws/blob/master/doc/ws.md 5 | 6 | const WebSocket = require("ws"); 7 | var AdmZip = require("adm-zip"); 8 | 9 | function *processZip(zipFileName) { 10 | var zip = new AdmZip("./foo.zip"); 11 | var zipEntries = zip.getEntries(); 12 | for (var i=0; i, // The file name to send 27 | * "data": , // The content of the file 28 | * } 29 | * ``` 30 | * @returns N/A 31 | */ 32 | function sendZipEntry(entry) { 33 | const ws = new WebSocket("ws://192.168.1.99:9080/upload"); 34 | ws.on("open", ()=>{ 35 | console.log("Sending file: " + entry.name); 36 | var file = { 37 | "name": entry.name 38 | //"length": 100 39 | } 40 | ws.send(JSON.stringify(file)); 41 | ws.send(entry.data); 42 | ws.close(); 43 | }); 44 | 45 | ws.on("error", (error)=>{ 46 | console.log("Error: %O", error); 47 | }); 48 | 49 | ws.on("close", (code)=>{ 50 | console.log("WS closed"); 51 | var nextEntry = it.next(); 52 | if (!nextEntry.done) { 53 | sendZipEntry(nextEntry.value); 54 | } 55 | }); 56 | } // sendZipEntry 57 | 58 | 59 | var it = processZip("./foo.zip"); 60 | var nextZip = it.next(); 61 | if (!nextZip.done) { 62 | sendZipEntry(nextZip.value); 63 | } 64 | -------------------------------------------------------------------------------- /gpio/interrupts/test_intr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test interrupt handling on a GPIO. 3 | * In this fragment we watch for a change on the input signal 4 | * of GPIO 25. When it goes high, an interrupt is raised which 5 | * adds a message to a queue which causes a task that is blocking 6 | * on the queue to wake up and process the interrupt. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "sdkconfig.h" 15 | 16 | static char tag[] = "test_intr"; 17 | static QueueHandle_t q1; 18 | 19 | #define TEST_GPIO (25) 20 | static void handler(void *args) { 21 | gpio_num_t gpio; 22 | gpio = TEST_GPIO; 23 | xQueueSendToBackFromISR(q1, &gpio, NULL); 24 | } 25 | 26 | void test1_task(void *ignore) { 27 | ESP_LOGD(tag, ">> test1_task"); 28 | gpio_num_t gpio; 29 | q1 = xQueueCreate(10, sizeof(gpio_num_t)); 30 | 31 | gpio_config_t gpioConfig; 32 | gpioConfig.pin_bit_mask = GPIO_SEL_25; 33 | gpioConfig.mode = GPIO_MODE_INPUT; 34 | gpioConfig.pull_up_en = GPIO_PULLUP_DISABLE; 35 | gpioConfig.pull_down_en = GPIO_PULLDOWN_ENABLE; 36 | gpioConfig.intr_type = GPIO_INTR_POSEDGE; 37 | gpio_config(&gpioConfig); 38 | 39 | gpio_install_isr_service(0); 40 | gpio_isr_handler_add(TEST_GPIO, handler, NULL ); 41 | while(1) { 42 | ESP_LOGD(tag, "Waiting on interrupt queue"); 43 | BaseType_t rc = xQueueReceive(q1, &gpio, portMAX_DELAY); 44 | ESP_LOGD(tag, "Woke from interrupt queue wait: %d", rc); 45 | } 46 | vTaskDelete(NULL); 47 | } 48 | -------------------------------------------------------------------------------- /hardware/accelerometers/README.md: -------------------------------------------------------------------------------- 1 | #Accelerometers 2 | An accelerometer detects acceleration and in some cases gyro scopic movement. 3 | 4 | See also the C++ class for MPU-6050 support. -------------------------------------------------------------------------------- /hardware/displays/Adafruit-GFX-Library/API.md: -------------------------------------------------------------------------------- 1 | * drawBitmap 2 | ``` 3 | drawBitmap(x, y, bitmap, w, h, color) 4 | ``` 5 | 6 | * drawChar 7 | Characters are 5x8 8 | ``` 9 | drawChar(x, y, c, color, bg, size) 10 | ``` 11 | 12 | * drawCircle 13 | ``` 14 | drawCircle(x, y, r, color) 15 | ``` 16 | 17 | * drawLine 18 | ``` 19 | drawLine(x1, y1, x2, y2, color) 20 | ``` 21 | 22 | * drawPixel 23 | ``` 24 | drawPixel(x,y,color) 25 | ``` 26 | 27 | * drawRect 28 | ``` 29 | drawRect(x, y, w, h, color) 30 | ``` 31 | 32 | * drawRoundRect 33 | ``` 34 | drawRoundRect(x, y, w, h, r, color) 35 | ``` 36 | 37 | * fillCircle 38 | ``` 39 | fillCircle(x, y, r, color) 40 | ``` 41 | 42 | * fillRect 43 | ``` 44 | fillRect(x, y, w, h, color) 45 | ``` 46 | 47 | * fillRoundRect 48 | ``` 49 | fillRoundRect(x, y, w, h, r, color) 50 | ``` 51 | 52 | * fillScreen 53 | ``` 54 | fillScreen(color) 55 | ``` 56 | 57 | * setCursor 58 | ``` 59 | setCursor(x, y) 60 | ``` 61 | 62 | * setRotation 63 | ``` 64 | setRotation(rotation) 65 | ``` 66 | 67 | * setTextColor 68 | ``` 69 | setTextColor(color) 70 | setTextColor(color, backgroundColor) 71 | ``` 72 | 73 | * setTextSize 74 | ``` 75 | setTextSize(size) 76 | ``` 77 | 78 | * setTextWrap 79 | ``` 80 | setTextWrap(w) 81 | ``` -------------------------------------------------------------------------------- /hardware/displays/Adafruit-GFX-Library/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. -------------------------------------------------------------------------------- /hardware/displays/Adafruit-GFX-Library/fontconvert/Makefile: -------------------------------------------------------------------------------- 1 | all: fontconvert 2 | 3 | CC = gcc 4 | CFLAGS = -Wall -I/usr/local/include/freetype2 -I/usr/include/freetype2 -I/usr/include 5 | LIBS = -lfreetype 6 | 7 | fontconvert: fontconvert.c 8 | $(CC) $(CFLAGS) $< $(LIBS) -o $@ 9 | strip $@ 10 | 11 | clean: 12 | rm -f fontconvert 13 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit-GFX-Library/fontconvert/makefonts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Ugly little Bash script, generates a set of .h files for GFX using 4 | # GNU FreeFont sources. There are three fonts: 'Mono' (Courier-like), 5 | # 'Sans' (Helvetica-like) and 'Serif' (Times-like); four styles: regular, 6 | # bold, oblique or italic, and bold+oblique or bold+italic; and four 7 | # sizes: 9, 12, 18 and 24 point. No real error checking or anything, 8 | # this just powers through all the combinations, calling the fontconvert 9 | # utility and redirecting the output to a .h file for each combo. 10 | 11 | # Adafruit_GFX repository does not include the source outline fonts 12 | # (huge zipfile, different license) but they're easily acquired: 13 | # http://savannah.gnu.org/projects/freefont/ 14 | 15 | convert=./fontconvert 16 | inpath=~/Desktop/freefont/ 17 | outpath=../Fonts/ 18 | fonts=(FreeMono FreeSans FreeSerif) 19 | styles=("" Bold Italic BoldItalic Oblique BoldOblique) 20 | sizes=(9 12 18 24) 21 | 22 | for f in ${fonts[*]} 23 | do 24 | for index in ${!styles[*]} 25 | do 26 | st=${styles[$index]} 27 | for si in ${sizes[*]} 28 | do 29 | infile=$inpath$f$st".ttf" 30 | if [ -f $infile ] # Does source combination exist? 31 | then 32 | outfile=$outpath$f$st$si"pt7b.h" 33 | # printf "%s %s %s > %s\n" $convert $infile $si $outfile 34 | $convert $infile $si > $outfile 35 | fi 36 | done 37 | done 38 | done 39 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit-GFX-Library/gfxfont.h: -------------------------------------------------------------------------------- 1 | // Font structures for newer Adafruit_GFX (1.1 and later). 2 | // Example fonts are included in 'Fonts' directory. 3 | // To use a font in your Arduino sketch, #include the corresponding .h 4 | // file and pass address of GFXfont struct to setFont(). Pass NULL to 5 | // revert to 'classic' fixed-space bitmap font. 6 | 7 | #ifndef _GFXFONT_H_ 8 | #define _GFXFONT_H_ 9 | 10 | typedef struct { // Data stored PER GLYPH 11 | uint16_t bitmapOffset; // Pointer into GFXfont->bitmap 12 | uint8_t width, height; // Bitmap dimensions in pixels 13 | uint8_t xAdvance; // Distance to advance cursor (x axis) 14 | int8_t xOffset, yOffset; // Dist from cursor pos to UL corner 15 | } GFXglyph; 16 | 17 | typedef struct { // Data stored for FONT AS A WHOLE: 18 | uint8_t *bitmap; // Glyph bitmaps, concatenated 19 | GFXglyph *glyph; // Glyph array 20 | uint8_t first, last; // ASCII extents 21 | uint8_t yAdvance; // Newline distance (y axis) 22 | } GFXfont; 23 | 24 | #endif // _GFXFONT_H_ 25 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit-GFX-Library/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit GFX Library 2 | version=1.1.5 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from. 6 | paragraph=Install this library in addition to the display library for your hardware. 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit-GFX-Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit-GFX-Library/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012 Adafruit Industries. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | - Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit-PCD8544-Nokia-5110-LCD-library/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit-PCD8544-Nokia-5110-LCD-library/API.md: -------------------------------------------------------------------------------- 1 | * begin 2 | ``` 3 | begin(contrast, bias) 4 | ``` 5 | The defaults are: 6 | * `contrast`: 40 7 | * `bias`: 4 8 | 9 | * clearDisplay 10 | Clear the existing content of the screen. 11 | ``` 12 | clearDisplay() 13 | ``` 14 | 15 | * display 16 | Synchronize what we want to display to the LCD. 17 | ``` 18 | display() 19 | ``` 20 | 21 | * setContrast 22 | ``` 23 | setContrast(val) 24 | ``` -------------------------------------------------------------------------------- /hardware/displays/Adafruit-PCD8544-Nokia-5110-LCD-library/README.txt: -------------------------------------------------------------------------------- 1 | This is a library for our Monochrome Nokia 5110 LCD Displays 2 | 3 | Pick one up today in the adafruit shop! 4 | ------> http://www.adafruit.com/products/338 5 | 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, check license.txt for more information 15 | All text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_PCD8544. Check that the Adafruit_PCD8544 folder contains Adafruit_PCD8544.cpp and Adafruit_PCD8544.h 18 | 19 | Place the Adafruit_PCD8544 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. 20 | 21 | You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from 22 | https://github.com/adafruit/Adafruit-GFX-Library 23 | and download/install that library as well -------------------------------------------------------------------------------- /hardware/displays/Adafruit-PCD8544-Nokia-5110-LCD-library/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. -------------------------------------------------------------------------------- /hardware/displays/Adafruit-PCD8544-Nokia-5110-LCD-library/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit PCD8544 Nokia 5110 LCD library 2 | version=1.0.1 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino driver for PC8544, most commonly found in small Nokia 5110's 6 | paragraph=Arduino driver for PC8544, most commonly found in small Nokia 5110's 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit-PCD8544-Nokia-5110-LCD-library/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1305-Library/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1305-Library/README.txt: -------------------------------------------------------------------------------- 1 | This is a library for our Monochrome OLEDs based on SSD1305 drivers 2 | 3 | Pick one up today in the adafruit shop! 4 | 5 | * https://www.adafruit.com/products/2675 6 | 7 | These displays use I2C or SPI to communicate 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, check license.txt for more information 15 | All text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1305. Check that the Adafruit_SSD1305 folder contains Adafruit_SSD1305.cpp and Adafruit_SSD1305.h 18 | 19 | Place the Adafruit_SSD1305 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. 20 | 21 | You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from 22 | https://github.com/adafruit/Adafruit-GFX-Library 23 | and download/install that library as well -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1305-Library/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1305-Library/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/API.md: -------------------------------------------------------------------------------- 1 | * begin 2 | ``` 3 | void begin() 4 | ``` 5 | 6 | * clearDisplay 7 | ``` 8 | void clearDisplay() 9 | ``` 10 | 11 | * dim 12 | ``` 13 | void dim(boolean) 14 | ``` 15 | 16 | * display 17 | ``` 18 | void display() 19 | ``` 20 | 21 | * invertDisplay 22 | Invert the visual of the display. Since this device is black and white which an off background of 23 | black the effect is to draw in black on a background of white. 24 | 25 | ``` 26 | void invertDisplay(boolean) 27 | ``` 28 | 29 | * startscrolldiagonalleft 30 | * startscrolldiagonalright 31 | * startscrollleft 32 | * startscrollright 33 | * scopscroll -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/README.md: -------------------------------------------------------------------------------- 1 | # Adafruit_SSD1306 2 | 3 | 4 | ## Compatibility 5 | 6 | MCU | Tested Works | Doesn't Work | Not Tested | Notes 7 | ------------------ | :----------: | :----------: | :---------: | ----- 8 | Atmega328 @ 16MHz | X | | | 9 | Atmega328 @ 12MHz | X | | | 10 | Atmega32u4 @ 16MHz | X | | | 11 | Atmega32u4 @ 8MHz | X | | | 12 | ESP8266 | X | | | change OLED_RESET to different pin if using default I2C pins D4/D5. 13 | Atmega2560 @ 16MHz | X | | | 14 | ATSAM3X8E | X | | | 15 | ATSAM21D | X | | | 16 | ATtiny85 @ 16MHz | | X | | 17 | ATtiny85 @ 8MHz | | X | | 18 | Intel Curie @ 32MHz | | | X | 19 | STM32F2 | | | X | 20 | 21 | * ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini 22 | * ATmega328 @ 12MHz : Adafruit Pro Trinket 3V 23 | * ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0 24 | * ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro 25 | * ESP8266 : Adafruit Huzzah 26 | * ATmega2560 @ 16MHz : Arduino Mega 27 | * ATSAM3X8E : Arduino Due 28 | * ATSAM21D : Arduino Zero, M0 Pro 29 | * ATtiny85 @ 16MHz : Adafruit Trinket 5V 30 | * ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V 31 | 32 | 33 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/README.txt: -------------------------------------------------------------------------------- 1 | This is a library for our Monochrome OLEDs based on SSD1306 drivers 2 | 3 | Pick one up today in the adafruit shop! 4 | ------> http://www.adafruit.com/category/63_98 5 | 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | Scrolling code contributed by Michael Gregg 15 | BSD license, check license.txt for more information 16 | All text above must be included in any redistribution 17 | 18 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1306. Check that the Adafruit_SSD1306 folder contains Adafruit_SSD1306.cpp and Adafruit_SSD1306.h 19 | 20 | Place the Adafruit_SSD1306 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. 21 | 22 | You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from 23 | https://github.com/adafruit/Adafruit-GFX-Library 24 | and download/install that library as well -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS=. -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/examples/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/examples/main/main.cpp: -------------------------------------------------------------------------------- 1 | #include "freertos/FreeRTOS.h" 2 | #include "esp_event.h" 3 | 4 | extern "C"{ 5 | void app_main(void); 6 | } 7 | void test_task(void*); 8 | 9 | void app_main(void) 10 | { 11 | xTaskCreate(&test_task, "test", 2048, NULL, 5, NULL); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit SSD1306 2 | version=1.1.2 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 OLEDs! 6 | paragraph=SSD1306 oled driver library for 'monochrome' 128x64 and 128x32 OLEDs! 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit_SSD1306 9 | architectures=* 10 | -------------------------------------------------------------------------------- /hardware/displays/Adafruit_SSD1306-Library/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /hardware/displays/U8G2/test_SSD1306.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "sdkconfig.h" 11 | #include "u8g2_esp32_hal.h" 12 | 13 | // CLK - GPIO14 14 | #define PIN_CLK 14 15 | 16 | // MOSI - GPIO 13 17 | #define PIN_MOSI 13 18 | 19 | // RESET - GPIO 26 20 | #define PIN_RESET 26 21 | 22 | // DC - GPIO 27 23 | #define PIN_DC 27 24 | 25 | // CS - GPIO 15 26 | #define PIN_CS 15 27 | static char tag[] = "test_SSD1306"; 28 | 29 | void task_test_SSD1306(void *ignore) { 30 | u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT; 31 | u8g2_esp32_hal.clk = PIN_CLK; 32 | u8g2_esp32_hal.mosi = PIN_MOSI; 33 | u8g2_esp32_hal.cs = PIN_CS; 34 | u8g2_esp32_hal.dc = PIN_DC; 35 | u8g2_esp32_hal.reset = PIN_RESET; 36 | u8g2_esp32_hal_init(u8g2_esp32_hal); 37 | 38 | 39 | u8g2_t u8g2; // a structure which will contain all the data for one display 40 | u8g2_Setup_ssd1306_128x64_noname_f( 41 | &u8g2, 42 | U8G2_R0, 43 | u8g2_esp32_spi_byte_cb, 44 | u8g2_esp32_gpio_and_delay_cb); // init u8g2 structure 45 | 46 | u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this, 47 | 48 | u8g2_SetPowerSave(&u8g2, 0); // wake up display 49 | u8g2_ClearBuffer(&u8g2); 50 | u8g2_DrawBox(&u8g2, 10,20, 20, 30); 51 | u8g2_SetFont(&u8g2, u8g2_font_ncenB14_tr); 52 | u8g2_DrawStr(&u8g2, 0,15,"Hello World!"); 53 | u8g2_SendBuffer(&u8g2); 54 | 55 | ESP_LOGD(tag, "All done!"); 56 | 57 | vTaskDelete(NULL); 58 | } 59 | -------------------------------------------------------------------------------- /hardware/displays/U8G2/test_SSD1306_i2c.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "sdkconfig.h" 11 | #include "u8g2_esp32_hal.h" 12 | 13 | // SDA - GPIO21 14 | #define PIN_SDA 21 15 | 16 | // SCL - GPIO22 17 | #define PIN_SCL 22 18 | 19 | static const char *TAG = "ssd1306"; 20 | 21 | void task_test_SSD1306i2c(void *ignore) { 22 | u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT; 23 | u8g2_esp32_hal.sda = PIN_SDA; 24 | u8g2_esp32_hal.scl = PIN_SCL; 25 | u8g2_esp32_hal_init(u8g2_esp32_hal); 26 | 27 | 28 | u8g2_t u8g2; // a structure which will contain all the data for one display 29 | u8g2_Setup_ssd1306_i2c_128x32_univision_f( 30 | &u8g2, 31 | U8G2_R0, 32 | //u8x8_byte_sw_i2c, 33 | u8g2_esp32_i2c_byte_cb, 34 | u8g2_esp32_gpio_and_delay_cb); // init u8g2 structure 35 | u8x8_SetI2CAddress(&u8g2.u8x8,0x78); 36 | 37 | ESP_LOGI(TAG, "u8g2_InitDisplay"); 38 | u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this, 39 | 40 | ESP_LOGI(TAG, "u8g2_SetPowerSave"); 41 | u8g2_SetPowerSave(&u8g2, 0); // wake up display 42 | ESP_LOGI(TAG, "u8g2_ClearBuffer"); 43 | u8g2_ClearBuffer(&u8g2); 44 | ESP_LOGI(TAG, "u8g2_DrawBox"); 45 | u8g2_DrawBox(&u8g2, 0, 26, 80,6); 46 | u8g2_DrawFrame(&u8g2, 0,26,100,6); 47 | 48 | ESP_LOGI(TAG, "u8g2_SetFont"); 49 | u8g2_SetFont(&u8g2, u8g2_font_ncenB14_tr); 50 | ESP_LOGI(TAG, "u8g2_DrawStr"); 51 | u8g2_DrawStr(&u8g2, 2,17,"Hi nkolban!"); 52 | ESP_LOGI(TAG, "u8g2_SendBuffer"); 53 | u8g2_SendBuffer(&u8g2); 54 | 55 | ESP_LOGI(TAG, "All done!"); 56 | 57 | vTaskDelete(NULL); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /hardware/displays/U8G2/u8g2_esp32_hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * u8g2_esp32_hal.h 3 | * 4 | * Created on: Feb 12, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef U8G2_ESP32_HAL_H_ 9 | #define U8G2_ESP32_HAL_H_ 10 | #include "u8g2.h" 11 | 12 | #include "driver/gpio.h" 13 | #include "driver/spi_master.h" 14 | #include "driver/i2c.h" 15 | 16 | #define U8G2_ESP32_HAL_UNDEFINED (-1) 17 | 18 | #define I2C_MASTER_NUM I2C_NUM_1 // I2C port number for master dev 19 | #define I2C_MASTER_TX_BUF_DISABLE 0 // I2C master do not need buffer 20 | #define I2C_MASTER_RX_BUF_DISABLE 0 // I2C master do not need buffer 21 | #define I2C_MASTER_FREQ_HZ 50000 // I2C master clock frequency 22 | #define ACK_CHECK_EN 0x1 // I2C master will check ack from slave 23 | #define ACK_CHECK_DIS 0x0 // I2C master will not check ack from slave 24 | 25 | typedef struct { 26 | gpio_num_t clk; 27 | gpio_num_t mosi; 28 | gpio_num_t sda; // data for I²C 29 | gpio_num_t scl; // clock for I²C 30 | gpio_num_t cs; 31 | gpio_num_t reset; 32 | gpio_num_t dc; 33 | } u8g2_esp32_hal_t ; 34 | 35 | #define U8G2_ESP32_HAL_DEFAULT {U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED } 36 | 37 | void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param); 38 | uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); 39 | uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); 40 | uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr); 41 | #endif /* U8G2_ESP32_HAL_H_ */ 42 | -------------------------------------------------------------------------------- /hardware/displays/tests/main.c: -------------------------------------------------------------------------------- 1 | #include "freertos/FreeRTOS.h" 2 | #include 3 | #include "esp_wifi.h" 4 | #include "esp_system.h" 5 | #include "esp_event.h" 6 | #include "esp_event_loop.h" 7 | #include "nvs_flash.h" 8 | #include "driver/gpio.h" 9 | #include 10 | #include 11 | 12 | static char tag[] = "mpcd"; 13 | 14 | extern void task_test_pcd8544(void *ignore); 15 | extern void task_test_ssd1306(void *ignore); 16 | extern void task_scroll_text(void *ignore); 17 | extern void task_scroll_text_ssd1306(void *ignore); 18 | extern void task_simple_tests_ssd1306(void *ignore); 19 | 20 | void app_main(void) 21 | { 22 | 23 | xTaskCreatePinnedToCore(&task_simple_tests_ssd1306, "task_simple_tests_ssd1306", 8048, NULL, 5, NULL, 0); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /hardware/displays/tests/scroll_text_pcd8544.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "Adafruit_GFX.h" 7 | #include "Adafruit_PCD8544.h" 8 | #include "sdkconfig.h" 9 | 10 | static char tag[] = "scroll_text"; 11 | 12 | static Adafruit_PCD8544 display = Adafruit_PCD8544( 13 | 14, // sclk 14 | 13, // MOSI 15 | 27, // D/C 16 | 15, // CS 17 | 26);// RST 18 | 19 | extern "C" { 20 | void task_scroll_text(void *ignore); 21 | } 22 | 23 | static void print(char *text) { 24 | while(*text != 0) { 25 | display.write(*text); 26 | text++; 27 | } 28 | } 29 | 30 | 31 | void task_scroll_text(void *ignore) { 32 | ESP_LOGD(tag, "start"); 33 | display.begin(); 34 | // init done 35 | 36 | // you can change the contrast around to adapt the display 37 | // for the best viewing! 38 | ESP_LOGD(tag, "set contrast"); 39 | display.setContrast(60); 40 | 41 | display.setTextWrap(0); 42 | int x; 43 | while(1) { 44 | for (x=0; x>-80; x-=6) { 45 | display.clearDisplay(); 46 | display.setCursor(x,5); 47 | print((char *)"192.168.113.254"); 48 | display.display(); 49 | vTaskDelay(150/portTICK_PERIOD_MS); 50 | //ESP_LOGD(tag, "next: %d", x); 51 | } 52 | } 53 | ESP_LOGD(tag, "end"); 54 | vTaskDelete(NULL); 55 | } 56 | -------------------------------------------------------------------------------- /hardware/displays/tests/scroll_text_ssd1306.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "../components/Adafruit_SSD1306-Library/Adafruit_SSD1306.h" 7 | #include "Adafruit_GFX.h" 8 | #include "sdkconfig.h" 9 | 10 | static char tag[] = "scroll_text"; 11 | 12 | Adafruit_SSD1306 display = Adafruit_SSD1306( 13 | 13, // MOSI 14 | 14, // SCLK 15 | 27, // DC 16 | 26, // RST 17 | 15); // CS 18 | 19 | extern "C" { 20 | void task_scroll_text_ssd1306(void *ignore); 21 | } 22 | 23 | static void print(char *text) { 24 | while(*text != 0) { 25 | display.write(*text); 26 | text++; 27 | } 28 | } 29 | 30 | 31 | void task_scroll_text_ssd1306(void *ignore) { 32 | ESP_LOGD(tag, "start"); 33 | display.begin(); 34 | // init done 35 | 36 | display.setTextWrap(0); 37 | display.setTextColor(WHITE); 38 | int x; 39 | while(1) { 40 | for (x=0; x>-80; x-=6) { 41 | display.clearDisplay(); 42 | display.setCursor(x,5); 43 | print((char *)"192.168.113.254"); 44 | display.display(); 45 | vTaskDelay(150/portTICK_PERIOD_MS); 46 | //ESP_LOGD(tag, "next: %d", x); 47 | } 48 | } 49 | ESP_LOGD(tag, "end"); 50 | vTaskDelete(NULL); 51 | } 52 | -------------------------------------------------------------------------------- /hardware/displays/tests/simple_tests_ssd1306.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "Adafruit_SSD1306.h" 7 | #include "Adafruit_GFX.h" 8 | #include "sdkconfig.h" 9 | 10 | static char tag[] = "simple_tests_SSD1306"; 11 | 12 | Adafruit_SSD1306 display = Adafruit_SSD1306( 13 | 13, // MOSI 14 | 14, // SCLK 15 | 27, // DC 16 | 26, // RST 17 | 15 // CS 18 | ); 19 | 20 | extern "C" { 21 | void task_simple_tests_ssd1306(void *ignore); 22 | } 23 | 24 | static void print(char *text) { 25 | while(*text != 0) { 26 | display.write(*text); 27 | text++; 28 | } 29 | } // print 30 | 31 | 32 | void task_simple_tests_ssd1306(void *ignore) { 33 | ESP_LOGD(tag, ">> task_simple_tests_ssd1306"); 34 | display.begin(); 35 | 36 | display.setTextWrap(0); 37 | display.setTextColor(WHITE); 38 | display.clearDisplay(); 39 | print((char *)"Hello from ESP32!"); 40 | display.setCursor(2, 10); 41 | print((char *)"It works!"); 42 | display.drawRect(0, 8, 9*6 + 2, 11, WHITE); 43 | 44 | display.fillCircle(128-24, 23, 8, WHITE); 45 | display.drawLine(72, 23, 92, 23, WHITE); 46 | display.drawLine(82, 17, 82, 29, WHITE); 47 | 48 | display.display(); 49 | ESP_LOGD(tag, "<< task_simple_tests_ssd1306"); 50 | vTaskDelete(NULL); 51 | } // task_simple_tests_ssd1306 52 | -------------------------------------------------------------------------------- /hardware/gps/Fragments/log_to_console.c: -------------------------------------------------------------------------------- 1 | #include "esp_log.h" 2 | #include "driver/uart.h" 3 | 4 | static char tag[] = "gps"; 5 | 6 | char *readLine(uart_port_t uart) { 7 | static char line[256]; 8 | int size; 9 | char *ptr = line; 10 | while(1) { 11 | size = uart_read_bytes(uart, (unsigned char *)ptr, 1, portMAX_DELAY); 12 | if (size == 1) { 13 | if (*ptr == '\n') { 14 | *ptr = 0; 15 | return line; 16 | } 17 | ptr++; 18 | } // End of read a character 19 | } // End of loop 20 | } // End of readLine 21 | 22 | void doGPS() { 23 | ESP_LOGD(tag, ">> doGPS"); 24 | uart_config_t myUartConfig; 25 | myUartConfig.baud_rate = 9600; 26 | myUartConfig.data_bits = UART_DATA_8_BITS; 27 | myUartConfig.parity = UART_PARITY_DISABLE; 28 | myUartConfig.stop_bits = UART_STOP_BITS_1; 29 | myUartConfig.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; 30 | myUartConfig.rx_flow_ctrl_thresh = 120; 31 | 32 | uart_param_config(UART_NUM_1, &myUartConfig); 33 | 34 | uart_set_pin(UART_NUM_1, 35 | UART_PIN_NO_CHANGE, // TX 36 | 34, // RX 37 | UART_PIN_NO_CHANGE, // RTS 38 | UART_PIN_NO_CHANGE // CTS 39 | ); 40 | 41 | uart_driver_install(UART_NUM_1, 2048, 2048, 10, 17, NULL); 42 | 43 | while(1) { 44 | char *line = readLine(UART_NUM_1); 45 | ESP_LOGD(tag, "%s", line); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hardware/gps/gps/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | -------------------------------------------------------------------------------- /hardware/gps/gps/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | gps 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | 26 | 27 | -------------------------------------------------------------------------------- /hardware/gps/gps/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := app-template 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /hardware/gps/gps/README.rst: -------------------------------------------------------------------------------- 1 | ESP-IDF template app 2 | ==================== 3 | 4 | This is a template application to be used with `Espressif IoT Development Framework`_ (ESP-IDF). 5 | 6 | Please check ESP-IDF docs for getting started instructions. 7 | 8 | Code in this repository is Copyright (C) 2016 Espressif Systems, licensed under the Apache License 2.0 as described in the file LICENSE. 9 | 10 | .. _Espressif IoT Development Framework: https://github.com/espressif/esp-idf 11 | 12 | 13 | -------------------------------------------------------------------------------- /hardware/gps/gps/components/.gitignore: -------------------------------------------------------------------------------- 1 | minmea 2 | 3 | -------------------------------------------------------------------------------- /hardware/gps/gps/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | include $(IDF_PATH)/make/component_common.mk 11 | -------------------------------------------------------------------------------- /hardware/gps/gps/main/main.c: -------------------------------------------------------------------------------- 1 | extern void doGPS(); 2 | 3 | int app_main(void) 4 | { 5 | doGPS(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /hardware/neopixels/README.md: -------------------------------------------------------------------------------- 1 | # Moved 2 | The class supporting the WS2812 pixels has moved to the `cpp_utils` folder. 3 | 4 | See also: 5 | * Github: [MartyMacGyver/ESP32-Digital-RGB-LED-Drivers](https://github.com/MartyMacGyver/ESP32-Digital-RGB-LED-Drivers) 6 | * Github: [FozzTexx/ws2812-demo](https://github.com/FozzTexx/ws2812-demo) -------------------------------------------------------------------------------- /hardware/nrf24/utility/ESP_IDF/NRF24_spi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The implementation of the ESP32 NRF24 SPI handler. 3 | */ 4 | #include "NRF24_spi.h" 5 | #include 6 | 7 | #include 8 | 9 | static SPI *spi; 10 | void NRF24_SPI::begin() { 11 | spi = new SPI(); 12 | spi->init(SPI::DEFAULT_MOSI_PIN, SPI::DEFAULT_MISO_PIN, SPI::DEFAULT_CLK_PIN, SPI::PIN_NOT_SET); 13 | } // begin 14 | 15 | 16 | /** 17 | * @brief Transfer some data in and out of SPI. 18 | * 19 | */ 20 | uint8_t NRF24_SPI::transfer(uint8_t data) { 21 | spi->transfer(&data, 1); 22 | return data; 23 | } // transfer 24 | -------------------------------------------------------------------------------- /hardware/nrf24/utility/ESP_IDF/NRF24_spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TMRh20 2015 3 | * SPI layer for RF24 <-> BCM2835 4 | */ 5 | /** 6 | * @file spi.h 7 | * \cond HIDDEN_SYMBOLS 8 | * Class declaration for SPI helper files 9 | */ 10 | #ifndef _SPI_H_INCLUDED 11 | #define _SPI_H_INCLUDED 12 | 13 | #include 14 | 15 | #define SPI_HAS_TRANSACTION 16 | #define MSBFIRST BCM2835_SPI_BIT_ORDER_MSBFIRST 17 | #define SPI_MODE0 BCM2835_SPI_MODE0 18 | #define RF24_SPI_SPEED BCM2835_SPI_SPEED_8MHZ 19 | 20 | #include 21 | 22 | class NRF24_SPI { 23 | public: 24 | 25 | static uint8_t transfer(uint8_t _data); 26 | // static void transfernb(char* tbuf, char* rbuf, uint32_t len); 27 | // static void transfern(char* buf, uint32_t len); 28 | 29 | static void begin(); 30 | // static void end(); 31 | 32 | // static void setBitOrder(uint8_t bit_order); 33 | // static void setDataMode(uint8_t data_mode); 34 | // static void setClockDivider(uint16_t spi_speed); 35 | // static void chipSelect(int csn_pin); 36 | 37 | //static void beginTransaction(SPISettings settings); 38 | // static void endTransaction(); 39 | 40 | }; 41 | 42 | extern NRF24_SPI _SPI; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /hardware/nrf24/utility/ESP_IDF/RF24_ESP_IDF.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "sdkconfig.h" 5 | #include "RF24_ESP_IDF.h" 6 | #include "NRF24_spi.h" 7 | 8 | void delay(int value) { 9 | vTaskDelay(value/portTICK_PERIOD_MS); 10 | } // delay 11 | 12 | 13 | void delayMicroseconds(int value) { 14 | return; 15 | } // delayMicroseconds 16 | 17 | 18 | void digitalWrite(int pin, int value) { 19 | gpio_set_level((gpio_num_t)pin, value); 20 | } // digitalWrite 21 | 22 | 23 | uint32_t millis() { 24 | return xTaskGetTickCount() * portTICK_PERIOD_MS; 25 | } // millis 26 | 27 | 28 | void pinMode(int pin, int mode) { 29 | gpio_config_t gpioConfig; 30 | gpioConfig.pin_bit_mask = (1 << pin); 31 | gpioConfig.mode = mode==OUTPUT?GPIO_MODE_OUTPUT:GPIO_MODE_INPUT; 32 | gpioConfig.pull_up_en = GPIO_PULLUP_DISABLE; 33 | gpioConfig.pull_down_en = GPIO_PULLDOWN_DISABLE; 34 | gpioConfig.intr_type = GPIO_INTR_DISABLE; 35 | gpio_config(&gpioConfig); 36 | } // pinMode 37 | 38 | NRF24_SPI _SPI; 39 | -------------------------------------------------------------------------------- /hardware/nrf24/utility/ESP_IDF/RF24_ESP_IDF.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RF24_ESP_IDF.h 3 | * 4 | * Created on: Feb 18, 2017 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef COMPONENTS_RF24_UTILITY_ESP_IDF_RF24_ESP_IDF_H_ 9 | #define COMPONENTS_RF24_UTILITY_ESP_IDF_RF24_ESP_IDF_H_ 10 | 11 | #define OUTPUT 0 12 | void delay(int value); 13 | void delayMicroseconds(int value); 14 | void digitalWrite(int pin, int value); 15 | uint32_t millis(); 16 | void pinMode(int pin, int mode); 17 | 18 | #endif /* COMPONENTS_RF24_UTILITY_ESP_IDF_RF24_ESP_IDF_H_ */ 19 | -------------------------------------------------------------------------------- /hardware/nrf24/utility/ESP_IDF/RF24_arch_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __ARCH_CONFIG_H__ 3 | #define __ARCH_CONFIG_H__ 4 | 5 | //#define RF24_LINUX 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // GCC a Arduino Missing 15 | #define _BV(x) (1<<(x)) 16 | #define pgm_read_word(p) (*(p)) 17 | #define pgm_read_byte(p) (*(p)) 18 | 19 | //typedef uint16_t prog_uint16_t; 20 | #define PSTR(x) (x) 21 | #define printf_P printf 22 | #define strlen_P strlen 23 | #define PROGMEM 24 | #define PRIPSTR "%s" 25 | 26 | #ifdef SERIAL_DEBUG 27 | #define IF_SERIAL_DEBUG(x) ({x;}) 28 | #else 29 | #define IF_SERIAL_DEBUG(x) 30 | #endif 31 | 32 | 33 | #define LOW 0 34 | #define HIGH 1 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /hardware/nrf24/utility/ESP_IDF/includes.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __RF24_INCLUDES_H__ 3 | #define __RF24_INCLUDES_H__ 4 | 5 | #define RF24_ESP_IDF 6 | #include "ESP_IDF/RF24_arch_config.h" 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /hardware/nrf24/utility/includes.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __RF24_INCLUDES_H__ 3 | #define __RF24_INCLUDES_H__ 4 | 5 | #define RF24_ESP_IDF 6 | #include "ESP_IDF/RF24_arch_config.h" 7 | #include "ESP_IDF/RF24_ESP_IDF.h" 8 | #include "ESP_IDF/NRF24_spi.h" 9 | #endif 10 | -------------------------------------------------------------------------------- /hardware/rtc/README.md: -------------------------------------------------------------------------------- 1 | #Real time clock 2 | This is an example of connecting a real time clock to the ESP32. -------------------------------------------------------------------------------- /i2c/scanner/README.md: -------------------------------------------------------------------------------- 1 | #I2C Scanner 2 | An I2C Scanner sends a start/stop request to each of the possible addresses on the bus. Those that are present return 3 | with an ACK. This can be used to detect the presence/absence of a device at that address. The results are logged 4 | to the serial output. Useful for testing for the existence of a device. -------------------------------------------------------------------------------- /i2c/scanner/i2cscanner.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "sdkconfig.h" 7 | 8 | #define SDA_PIN 18 9 | #define SCL_PIN 19 10 | 11 | static char tag[] = "i2cscanner"; 12 | 13 | void task_i2cscanner(void *ignore) { 14 | ESP_LOGD(tag, ">> i2cScanner"); 15 | i2c_config_t conf; 16 | conf.mode = I2C_MODE_MASTER; 17 | conf.sda_io_num = SDA_PIN; 18 | conf.scl_io_num = SCL_PIN; 19 | conf.sda_pullup_en = GPIO_PULLUP_ENABLE; 20 | conf.scl_pullup_en = GPIO_PULLUP_ENABLE; 21 | conf.master.clk_speed = 100000; 22 | i2c_param_config(I2C_NUM_0, &conf); 23 | 24 | i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0); 25 | 26 | int i; 27 | esp_err_t espRc; 28 | printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); 29 | printf("00: "); 30 | for (i=3; i< 0x78; i++) { 31 | i2c_cmd_handle_t cmd = i2c_cmd_link_create(); 32 | i2c_master_start(cmd); 33 | i2c_master_write_byte(cmd, (i << 1) | I2C_MASTER_WRITE, 1 /* expect ack */); 34 | i2c_master_stop(cmd); 35 | 36 | espRc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS); 37 | if (i%16 == 0) { 38 | printf("\n%.2x:", i); 39 | } 40 | if (espRc == 0) { 41 | printf(" %.2x", i); 42 | } else { 43 | printf(" --"); 44 | } 45 | //ESP_LOGD(tag, "i=%d, rc=%d (0x%x)", i, espRc, espRc); 46 | i2c_cmd_link_delete(cmd); 47 | } 48 | printf("\n"); 49 | vTaskDelete(NULL); 50 | } 51 | -------------------------------------------------------------------------------- /memory/dma/DMA.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DMA.h 3 | * 4 | * Created on: May 27, 2018 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_DMA_H_ 9 | #define MAIN_DMA_H_ 10 | 11 | class DMA { 12 | public: 13 | DMA(); 14 | virtual ~DMA(); 15 | void clearInterupts(); 16 | void dumpBuffer(); 17 | void dumpStatus(); 18 | void reset(); 19 | void setCameraMode(); 20 | void start(); 21 | void startRX(); 22 | void stopRX(); 23 | 24 | }; 25 | 26 | #endif /* MAIN_DMA_H_ */ 27 | -------------------------------------------------------------------------------- /memory/dma/DMA_GPIO.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DMA_GPIO.h 3 | * 4 | * Created on: May 27, 2018 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_DMA_GPIO_H_ 9 | #define MAIN_DMA_GPIO_H_ 10 | 11 | 12 | 13 | #endif /* MAIN_DMA_GPIO_H_ */ 14 | -------------------------------------------------------------------------------- /memory/dma/GPIODriver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GPIODriver.h 3 | * 4 | * Created on: May 27, 2018 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_GPIODRIVER_H_ 9 | #define MAIN_GPIODRIVER_H_ 10 | 11 | class GPIODriver { 12 | public: 13 | GPIODriver(); 14 | virtual ~GPIODriver(); 15 | void run(); 16 | }; 17 | 18 | #endif /* MAIN_GPIODRIVER_H_ */ 19 | -------------------------------------------------------------------------------- /memory/dma/main.cpp: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | void app_main(void); 3 | } 4 | 5 | extern void test_linenoise(); 6 | extern void test_argtable(); 7 | extern void test_console(); 8 | 9 | void app_main(void) 10 | { 11 | //test_linenoise(); 12 | //test_argtable(); 13 | test_console(); 14 | } 15 | -------------------------------------------------------------------------------- /memory/esp32_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * esp32_memory.h 3 | * 4 | * Created on: Dec 9, 2016 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_ESP32_MEMORY_H_ 9 | #define MAIN_ESP32_MEMORY_H_ 10 | 11 | #include 12 | #include 13 | 14 | static uint32_t _heapFreeBefore; 15 | static uint32_t _counter = 0; 16 | 17 | #define HEAP_CHANGE_START() _heapFreeBefore = esp_get_free_heap_size() 18 | #define HEAP_CHANGE_END(_EYECATCHER) { \ 19 | uint32_t newSize = esp_get_free_heap_size(); \ 20 | uint32_t value = _heapFreeBefore - newSize; \ 21 | if (value !=0) { \ 22 | ESP_LOGD("memory", _EYECATCHER ": Heap changed by %d, new size: %d, counter: %d", value, newSize, _counter); \ 23 | _counter = 0; \ 24 | } else { _counter++; }\ 25 | } 26 | 27 | 28 | #endif /* MAIN_ESP32_MEMORY_H_ */ 29 | -------------------------------------------------------------------------------- /mongoose/webserver/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | -------------------------------------------------------------------------------- /mongoose/webserver/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := app-template 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /mongoose/webserver/README.md: -------------------------------------------------------------------------------- 1 | # mongoose/webserver 2 | This snippet provides a simple Webserver using the Mongoose library on the ESP32. 3 | It provides two URL endpoints: 4 | 5 | * `/time` - Returns a JSON encoded time since startup. 6 | * `/test1.html` - Returns a simple HTML web page. 7 | 8 | The web page has been hard-coded into the application. We used the `xxd` tool on Linux 9 | which takes as input a binary file (eg. an HTML source file) and generates a header file 10 | that exposes the data. For example: 11 | 12 | ``` 13 | $ xxd -i test1.html test1_html.h 14 | ``` -------------------------------------------------------------------------------- /mongoose/webserver/components/.gitignore: -------------------------------------------------------------------------------- 1 | mongoose 2 | -------------------------------------------------------------------------------- /mongoose/webserver/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | CFLAGS += -DCS_PLATFORM=15 -DMG_DISABLE_DIRECTORY_LISTING=1 -DMG_DISABLE_DAV=1 -DMG_DISABLE_CGI=1 10 | include $(IDF_PATH)/make/component_common.mk 11 | -------------------------------------------------------------------------------- /mongoose/webserver/main/test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Test ESP32 page 6 | 7 | 8 |

Hello from ESP32

9 |

Simple ESP32 page

10 | 11 | -------------------------------------------------------------------------------- /mongoose/webserver/main/test1_html.h: -------------------------------------------------------------------------------- 1 | unsigned char test1_html[] = { 2 | 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, 0x68, 0x74, 3 | 0x6d, 0x6c, 0x3e, 0x0a, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0a, 0x20, 4 | 0x20, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 5 | 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x20, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, 6 | 0x74, 0x3d, 0x22, 0x55, 0x54, 0x46, 0x2d, 0x38, 0x22, 0x3e, 0x0a, 0x20, 7 | 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x54, 0x65, 8 | 0x73, 0x74, 0x20, 0x45, 0x53, 0x50, 0x33, 0x32, 0x20, 0x70, 0x61, 0x67, 9 | 0x65, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x0a, 0x20, 0x20, 10 | 0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0a, 0x20, 0x20, 0x3c, 0x62, 11 | 0x6f, 0x64, 0x79, 0x3e, 0x0a, 0x20, 0x20, 0x09, 0x3c, 0x68, 0x31, 0x3e, 12 | 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x45, 13 | 0x53, 0x50, 0x33, 0x32, 0x3c, 0x2f, 0x68, 0x31, 0x3e, 0x0a, 0x20, 0x20, 14 | 0x09, 0x3c, 0x70, 0x3e, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x45, 15 | 0x53, 0x50, 0x33, 0x32, 0x20, 0x70, 0x61, 0x67, 0x65, 0x3c, 0x2f, 0x70, 16 | 0x3e, 0x0a, 0x20, 0x20, 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0a, 17 | 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e 18 | }; 19 | unsigned int test1_html_len = 187; 20 | -------------------------------------------------------------------------------- /networking/FTPServer/main.cpp: -------------------------------------------------------------------------------- 1 | #include "FTPServer.h" 2 | #include 3 | 4 | 5 | int main(int argc, char* argv[]) { 6 | printf("FTPServer starting!\n"); 7 | FTPServer *ftpServer = new FTPServer(); 8 | ftpServer->setCallbacks(new FTPFileCallbacks()); 9 | //ftpServer->setCredentials("user", "pass"); 10 | ftpServer->setPort(9876); 11 | ftpServer->start(); 12 | } 13 | -------------------------------------------------------------------------------- /networking/bootwifi/BootWiFi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BootWiFi.h 3 | * 4 | * Created on: Nov 25, 2016 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_BOOTWIFI_H_ 9 | #define MAIN_BOOTWIFI_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | typedef void (*bootwifi_callback_t)(int rc); 16 | class BootWifiEventHandler; 17 | 18 | class BootWiFi { 19 | private: 20 | friend BootWifiEventHandler; 21 | void bootWiFi2(); 22 | WiFi m_wifi; 23 | HttpServer m_httpServer; 24 | bool m_httpServerStarted; 25 | std::string m_ssid; 26 | std::string m_password; 27 | uint8_t m_apConnectionStatus; // receives the connection status. ESP_OK = received SYSTEM_EVENT_STA_GOT_IP event. 28 | FreeRTOS::Semaphore m_completeSemaphore = FreeRTOS::Semaphore("completeSemaphore"); 29 | 30 | public: 31 | BootWiFi(); 32 | void setAccessPointCredentials(std::string ssid, std::string password); 33 | uint8_t boot(); 34 | }; 35 | 36 | #endif /* MAIN_BOOTWIFI_H_ */ 37 | -------------------------------------------------------------------------------- /networking/bootwifi/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | COMPONENT_ADD_INCLUDEDIRS=. -------------------------------------------------------------------------------- /networking/bootwifi/selectAP.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Select WiFi 6 | 7 | 8 | 9 |
10 |

Select WiFi

11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
SSID:
Password:
IP address:
Gateway address:
Netmask:
36 |

37 | 38 |

39 |
40 |
41 | The IP address, gateway address and netmask are optional. If not supplied 42 | these values will be issued by the WiFi access point. 43 |
44 |
45 | 46 | 47 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | embedded-C 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | 26 | 27 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/.settings/org.eclipse.cdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | formatter_profile=org.eclipse.cdt.ui.default.allman_profile 3 | formatter_settings_version=1 4 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/Debug/makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | -include ../makefile.init 6 | 7 | RM := rm -rf 8 | 9 | # All of the sources participating in the build are defined here 10 | -include sources.mk 11 | -include MQTTPacket/src/subdir.mk 12 | -include MQTTPacket/samples/subdir.mk 13 | -include subdir.mk 14 | -include objects.mk 15 | 16 | ifneq ($(MAKECMDGOALS),clean) 17 | ifneq ($(strip $(C_DEPS)),) 18 | -include $(C_DEPS) 19 | endif 20 | endif 21 | 22 | -include ../makefile.defs 23 | 24 | # Add inputs and outputs from these tool invocations to the build variables 25 | 26 | # All Target 27 | all: libembedded-C.so 28 | 29 | # Tool invocations 30 | libembedded-C.so: $(OBJS) $(USER_OBJS) 31 | @echo 'Building target: $@' 32 | @echo 'Invoking: GCC C Linker' 33 | gcc -shared -o "libembedded-C.so" $(OBJS) $(USER_OBJS) $(LIBS) 34 | @echo 'Finished building target: $@' 35 | @echo ' ' 36 | 37 | # Other Targets 38 | clean: 39 | -$(RM) $(C_DEPS)$(LIBRARIES)$(OBJS) libembedded-C.so 40 | -@echo ' ' 41 | 42 | .PHONY: all clean dependents 43 | .SECONDARY: 44 | 45 | -include ../makefile.targets 46 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/Debug/objects.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | USER_OBJS := 6 | 7 | LIBS := 8 | 9 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/Debug/sources.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | ASM_SRCS := 6 | OBJ_SRCS := 7 | S_UPPER_SRCS := 8 | C_SRCS := 9 | O_SRCS := 10 | C_DEPS := 11 | LIBRARIES := 12 | OBJS := 13 | 14 | # Every subdirectory with source files must be described here 15 | SUBDIRS := \ 16 | MQTTPacket/src \ 17 | MQTTPacket/samples \ 18 | 19 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/Debug/src/MQTTDeserializeConnect.d: -------------------------------------------------------------------------------- 1 | src/MQTTDeserializeConnect.d src/MQTTDeserializeConnect.o: \ 2 | ../src/MQTTDeserializeConnect.c ../src/StackTrace.h 3 | 4 | ../src/StackTrace.h: 5 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/Debug/src/subdir.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | # Add inputs and outputs from these tool invocations to the build variables 6 | C_SRCS += \ 7 | ../src/MQTTConnectClient.c \ 8 | ../src/MQTTConnectServer.c \ 9 | ../src/MQTTDeserializePublish.c \ 10 | ../src/MQTTPacket.c \ 11 | ../src/MQTTSerializePublish.c \ 12 | ../src/MQTTSubscribeClient.c \ 13 | ../src/MQTTSubscribeServer.c \ 14 | ../src/MQTTUnsubscribeClient.c \ 15 | ../src/MQTTUnsubscribeServer.c 16 | 17 | C_DEPS += \ 18 | ./src/MQTTConnectClient.d \ 19 | ./src/MQTTConnectServer.d \ 20 | ./src/MQTTDeserializePublish.d \ 21 | ./src/MQTTPacket.d \ 22 | ./src/MQTTSerializePublish.d \ 23 | ./src/MQTTSubscribeClient.d \ 24 | ./src/MQTTSubscribeServer.d \ 25 | ./src/MQTTUnsubscribeClient.d \ 26 | ./src/MQTTUnsubscribeServer.d 27 | 28 | OBJS += \ 29 | ./src/MQTTConnectClient.o \ 30 | ./src/MQTTConnectServer.o \ 31 | ./src/MQTTDeserializePublish.o \ 32 | ./src/MQTTPacket.o \ 33 | ./src/MQTTSerializePublish.o \ 34 | ./src/MQTTSubscribeClient.o \ 35 | ./src/MQTTSubscribeServer.o \ 36 | ./src/MQTTUnsubscribeClient.o \ 37 | ./src/MQTTUnsubscribeServer.o 38 | 39 | 40 | # Each subdirectory must supply rules for building sources it contributes 41 | src/%.o: ../src/%.c 42 | @echo 'Building file: $<' 43 | @echo 'Invoking: GCC C Compiler' 44 | gcc -I"/home/icraggs/work/paho/org.eclipse.paho.mqtt.embedded-c/src" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 45 | @echo 'Finished building: $<' 46 | @echo ' ' 47 | 48 | 49 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/ESP32_Sample/mqtt_paho.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #include "MQTTClient.h" 8 | #include "sdkconfig.h" 9 | 10 | static char tag[] = "mqtt_paho"; 11 | static unsigned char sendBuf[1000]; 12 | static unsigned char readBuf[1000]; 13 | Network network; 14 | static void messageHandler_func(MessageData *md) { 15 | ESP_LOGD(tag, "Subscription received!: %.*s", md->topicName->lenstring.len, md->topicName->lenstring.data); 16 | } 17 | 18 | void task_paho(void *ignore) { 19 | ESP_LOGD(tag, "Starting ..."); 20 | int rc; 21 | MQTTClient client; 22 | NetworkInit(&network); 23 | ESP_LOGD(tag, "NetworkConnect ..."); 24 | NetworkConnect(&network, "192.168.1.105", 1883); 25 | ESP_LOGD(tag, "MQTTClientInit ..."); 26 | MQTTClientInit(&client, &network, 27 | 1000, // command_timeout_ms 28 | sendBuf, //sendbuf, 29 | sizeof(sendBuf), //sendbuf_size, 30 | readBuf, //readbuf, 31 | sizeof(readBuf) //readbuf_size 32 | ); 33 | 34 | MQTTString clientId = MQTTString_initializer; 35 | clientId.cstring = "MYCLIENT1"; 36 | 37 | MQTTPacket_connectData data = MQTTPacket_connectData_initializer; 38 | data.clientID = clientId; 39 | data.willFlag = 0; 40 | data.MQTTVersion = 3; 41 | data.keepAliveInterval = 0; 42 | data.cleansession = 1; 43 | 44 | ESP_LOGD(tag, "MQTTConnect ..."); 45 | rc = MQTTConnect(&client, &data); 46 | if (rc != SUCCESS) { 47 | ESP_LOGE(tag, "MQTTConnect: %d", rc); 48 | } 49 | 50 | ESP_LOGD(tag, "MQTTSubscribe ..."); 51 | rc = MQTTSubscribe(&client, "test1", QOS0, messageHandler_func); 52 | if (rc != SUCCESS) { 53 | ESP_LOGE(tag, "MQTTSubscribe: %d", rc); 54 | } 55 | while(1) { 56 | MQTTYield(&client, 1000); 57 | } 58 | vTaskDelete(NULL); 59 | } 60 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient-C/samples/linux/build.sh: -------------------------------------------------------------------------------- 1 | cp ../../src/MQTTClient.c . 2 | sed -e 's/""/"MQTTLinux.h"/g' ../../src/MQTTClient.h > MQTTClient.h 3 | gcc stdoutsub.c -I ../../src -I ../../src/linux -I ../../../MQTTPacket/src MQTTClient.c ../../src/linux/MQTTLinux.c ../../../MQTTPacket/src/MQTTFormat.c ../../../MQTTPacket/src/MQTTPacket.c ../../../MQTTPacket/src/MQTTDeserializePublish.c ../../../MQTTPacket/src/MQTTConnectClient.c ../../../MQTTPacket/src/MQTTSubscribeClient.c ../../../MQTTPacket/src/MQTTSerializePublish.c -o stdoutsub ../../../MQTTPacket/src/MQTTConnectServer.c ../../../MQTTPacket/src/MQTTSubscribeServer.c ../../../MQTTPacket/src/MQTTUnsubscribeServer.c ../../../MQTTPacket/src/MQTTUnsubscribeClient.c -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient-C/src/cc3200/MQTTCC3200.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Allan Stockdill-Mander - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef __MQTT_CC3200_ 18 | #define __MQTT_CC3200_ 19 | 20 | #include "simplelink.h" 21 | #include "netapp.h" 22 | #include "socket.h" 23 | #include "hw_types.h" 24 | #include "systick.h" 25 | 26 | typedef struct Timer Timer; 27 | 28 | struct Timer { 29 | unsigned long systick_period; 30 | unsigned long end_time; 31 | }; 32 | 33 | typedef struct Network Network; 34 | 35 | struct Network 36 | { 37 | int my_socket; 38 | int (*mqttread) (Network*, unsigned char*, int, int); 39 | int (*mqttwrite) (Network*, unsigned char*, int, int); 40 | void (*disconnect) (Network*); 41 | }; 42 | 43 | char expired(Timer*); 44 | void countdown_ms(Timer*, unsigned int); 45 | void countdown(Timer*, unsigned int); 46 | int left_ms(Timer*); 47 | 48 | void InitTimer(Timer*); 49 | 50 | int cc3200_read(Network*, unsigned char*, int, int); 51 | int cc3200_write(Network*, unsigned char*, int, int); 52 | void cc3200_disconnect(Network*); 53 | void NewNetwork(Network*); 54 | 55 | int ConnectNetwork(Network*, char*, int); 56 | int TLSConnectNetwork(Network*, char*, int, SlSockSecureFiles_t*, unsigned char, unsigned int, char); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/build.sh: -------------------------------------------------------------------------------- 1 | g++ hello.cpp -I ../../src/ -I ../../src/linux -I ../../../MQTTPacket/src ../../../MQTTPacket/src/MQTTPacket.c ../../../MQTTPacket/src/MQTTDeserializePublish.c ../../../MQTTPacket/src/MQTTConnectClient.c ../../../MQTTPacket/src/MQTTSubscribeClient.c ../../../MQTTPacket/src/MQTTSerializePublish.c ../../../MQTTPacket/src/MQTTUnsubscribeClient.c -o hello 2 | 3 | g++ -g stdoutsub.cpp -I ../../src -I ../../src/linux -I ../../../MQTTPacket/src ../../../MQTTPacket/src/MQTTFormat.c ../../../MQTTPacket/src/MQTTPacket.c ../../../MQTTPacket/src/MQTTDeserializePublish.c ../../../MQTTPacket/src/MQTTConnectClient.c ../../../MQTTPacket/src/MQTTSubscribeClient.c ../../../MQTTPacket/src/MQTTSerializePublish.c -o stdoutsub ../../../MQTTPacket/src/MQTTConnectServer.c ../../../MQTTPacket/src/MQTTSubscribeServer.c ../../../MQTTPacket/src/MQTTUnsubscribeServer.c ../../../MQTTPacket/src/MQTTUnsubscribeClient.c 4 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/hello -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/stdoutsub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/networking/mqtt/paho_mqtt_embedded_c/MQTTClient/samples/linux/stdoutsub -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient/src/MQTTLogging.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(MQTT_LOGGING_H) 18 | #define MQTT_LOGGING_H 19 | 20 | #define STREAM stdout 21 | #if !defined(DEBUG) 22 | #define DEBUG(...) \ 23 | {\ 24 | fprintf(STREAM, "DEBUG: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 25 | fprintf(STREAM, ##__VA_ARGS__); \ 26 | fflush(STREAM); \ 27 | } 28 | #endif 29 | #if !defined(LOG) 30 | #define LOG(...) \ 31 | {\ 32 | fprintf(STREAM, "LOG: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 33 | fprintf(STREAM, ##__VA_ARGS__); \ 34 | fflush(STREAM); \ 35 | } 36 | #endif 37 | #if !defined(WARN) 38 | #define WARN(...) \ 39 | { \ 40 | fprintf(STREAM, "WARN: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 41 | fprintf(STREAM, ##__VA_ARGS__); \ 42 | fflush(STREAM); \ 43 | } 44 | #endif 45 | #if !defined(ERROR) 46 | #define ERROR(...) \ 47 | { \ 48 | fprintf(STREAM, "ERROR: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 49 | fprintf(STREAM, ##__VA_ARGS__); \ 50 | fflush(STREAM); \ 51 | exit(1); \ 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient/src/arduino/Countdown.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(COUNTDOWN_H) 18 | #define COUNTDOWN_H 19 | 20 | class Countdown 21 | { 22 | public: 23 | Countdown() 24 | { 25 | interval_end_ms = 0L; 26 | } 27 | 28 | Countdown(int ms) 29 | { 30 | countdown_ms(ms); 31 | } 32 | 33 | bool expired() 34 | { 35 | return (interval_end_ms > 0L) && (millis() >= interval_end_ms); 36 | } 37 | 38 | void countdown_ms(unsigned long ms) 39 | { 40 | interval_end_ms = millis() + ms; 41 | } 42 | 43 | void countdown(int seconds) 44 | { 45 | countdown_ms((unsigned long)seconds * 1000L); 46 | } 47 | 48 | int left_ms() 49 | { 50 | return interval_end_ms - millis(); 51 | } 52 | 53 | private: 54 | unsigned long interval_end_ms; 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTEthernet.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(MQTTETHERNET_H) 18 | #define MQTTETHERNET_H 19 | 20 | #include "MQTT_mbed.h" 21 | #include "EthernetInterface.h" 22 | #include "MQTTSocket.h" 23 | 24 | class MQTTEthernet : public MQTTSocket 25 | { 26 | public: 27 | MQTTEthernet() 28 | { 29 | eth.init(); // Use DHCP 30 | eth.connect(); 31 | } 32 | 33 | private: 34 | 35 | EthernetInterface eth; 36 | 37 | }; 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTSocket.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #if !defined(MQTTSOCKET_H) 18 | #define MQTTSOCKET_H 19 | 20 | #include "MQTT_mbed.h" 21 | #include "TCPSocketConnection.h" 22 | 23 | class MQTTSocket 24 | { 25 | public: 26 | int connect(char* hostname, int port, int timeout=1000) 27 | { 28 | mysock.set_blocking(false, timeout); // 1 second Timeout 29 | return mysock.connect(hostname, port); 30 | } 31 | 32 | int read(unsigned char* buffer, int len, int timeout) 33 | { 34 | mysock.set_blocking(false, timeout); 35 | return mysock.receive((char*)buffer, len); 36 | } 37 | 38 | int write(unsigned char* buffer, int len, int timeout) 39 | { 40 | mysock.set_blocking(false, timeout); 41 | return mysock.send((char*)buffer, len); 42 | } 43 | 44 | int disconnect() 45 | { 46 | return mysock.close(); 47 | } 48 | 49 | private: 50 | 51 | TCPSocketConnection mysock; 52 | 53 | }; 54 | 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/samples/build: -------------------------------------------------------------------------------- 1 | gcc -Wall -c transport.c -Os -s 2 | gcc qos0pub.c transport.o -I ../src ../src/MQTTConnectClient.c ../src/MQTTSerializePublish.c ../src/MQTTPacket.c -o qos0pub -Os -s 3 | 4 | gcc pub0sub1.c transport.o -I ../src ../src/MQTTConnectClient.c ../src/MQTTSerializePublish.c ../src/MQTTPacket.c ../src/MQTTSubscribeClient.c -o pub0sub1 ../src/MQTTDeserializePublish.c -Os -s ../src/MQTTConnectServer.c ../src/MQTTSubscribeServer.c ../src/MQTTUnsubscribeServer.c ../src/MQTTUnsubscribeClient.c -ggdb 5 | gcc pub0sub1_nb.c transport.o -I ../src ../src/MQTTConnectClient.c ../src/MQTTSerializePublish.c ../src/MQTTPacket.c ../src/MQTTSubscribeClient.c -o pub0sub1_nb ../src/MQTTDeserializePublish.c -Os -s ../src/MQTTConnectServer.c ../src/MQTTSubscribeServer.c ../src/MQTTUnsubscribeServer.c ../src/MQTTUnsubscribeClient.c -ggdb 6 | 7 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/samples/null.c: -------------------------------------------------------------------------------- 1 | int main(int argc, char** argv) 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/samples/transport.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Sergio R. Caprile - "commonalization" from prior samples and/or documentation extension 16 | *******************************************************************************/ 17 | 18 | int transport_sendPacketBuffer(int sock, unsigned char* buf, int buflen); 19 | int transport_getdata(unsigned char* buf, int count); 20 | int transport_getdatanb(void *sck, unsigned char* buf, int count); 21 | int transport_open(char* host, int port); 22 | int transport_close(int sock); 23 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/src/MQTTPublish.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Xiang Rong - 442039 Add makefile to Embedded C client 16 | *******************************************************************************/ 17 | 18 | #ifndef MQTTPUBLISH_H_ 19 | #define MQTTPUBLISH_H_ 20 | 21 | #if !defined(DLLImport) 22 | #define DLLImport 23 | #endif 24 | #if !defined(DLLExport) 25 | #define DLLExport 26 | #endif 27 | 28 | DLLExport int MQTTSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid, 29 | MQTTString topicName, unsigned char* payload, int payloadlen); 30 | 31 | DLLExport int MQTTDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName, 32 | unsigned char** payload, int* payloadlen, unsigned char* buf, int len); 33 | 34 | DLLExport int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid); 35 | DLLExport int MQTTSerialize_pubrel(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid); 36 | DLLExport int MQTTSerialize_pubcomp(unsigned char* buf, int buflen, unsigned short packetid); 37 | 38 | #endif /* MQTTPUBLISH_H_ */ 39 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/src/MQTTSubscribe.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Xiang Rong - 442039 Add makefile to Embedded C client 16 | *******************************************************************************/ 17 | 18 | #ifndef MQTTSUBSCRIBE_H_ 19 | #define MQTTSUBSCRIBE_H_ 20 | 21 | #if !defined(DLLImport) 22 | #define DLLImport 23 | #endif 24 | #if !defined(DLLExport) 25 | #define DLLExport 26 | #endif 27 | 28 | DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, 29 | int count, MQTTString topicFilters[], int requestedQoSs[]); 30 | 31 | DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, 32 | int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len); 33 | 34 | DLLExport int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs); 35 | 36 | DLLExport int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int len); 37 | 38 | 39 | #endif /* MQTTSUBSCRIBE_H_ */ 40 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/src/MQTTUnsubscribe.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Ian Craggs - initial API and implementation and/or initial documentation 15 | * Xiang Rong - 442039 Add makefile to Embedded C client 16 | *******************************************************************************/ 17 | 18 | #ifndef MQTTUNSUBSCRIBE_H_ 19 | #define MQTTUNSUBSCRIBE_H_ 20 | 21 | #if !defined(DLLImport) 22 | #define DLLImport 23 | #endif 24 | #if !defined(DLLExport) 25 | #define DLLExport 26 | #endif 27 | 28 | DLLExport int MQTTSerialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, 29 | int count, MQTTString topicFilters[]); 30 | 31 | DLLExport int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int max_count, int* count, MQTTString topicFilters[], 32 | unsigned char* buf, int len); 33 | 34 | DLLExport int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid); 35 | 36 | DLLExport int MQTTDeserialize_unsuback(unsigned short* packetid, unsigned char* buf, int len); 37 | 38 | #endif /* MQTTUNSUBSCRIBE_H_ */ 39 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/MQTTPacket/test/build_test: -------------------------------------------------------------------------------- 1 | gcc -Wall test1.c -o test1 -I../src ../src/MQTTConnectClient.c ../src/MQTTConnectServer.c ../src/MQTTPacket.c ../src/MQTTSerializePublish.c ../src/MQTTDeserializePublish.c ../src/MQTTSubscribeServer.c ../src/MQTTSubscribeClient.c ../src/MQTTUnsubscribeServer.c ../src/MQTTUnsubscribeClient.c 2 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | About 5 | 6 | 7 |

About This Content

8 | 9 |

December 9, 2013

10 |

License

11 | 12 |

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise 13 | indicated below, the Content is provided to you under the terms and conditions of the 14 | Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL"). 15 | A copy of the EPL is available at 16 | http://www.eclipse.org/legal/epl-v10.html 17 | and a copy of the EDL is available at 18 | http://www.eclipse.org/org/documents/edl-v10.php. 19 | For purposes of the EPL, "Program" will mean the Content.

20 | 21 |

If you did not receive this Content directly from the Eclipse Foundation, the Content is 22 | being redistributed by another party ("Redistributor") and different terms and conditions may 23 | apply to your use of any object code in the Content. Check the Redistributor's license that was 24 | provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise 25 | indicated below, the terms and conditions of the EPL still apply to any source code in the Content 26 | and such source code may be obtained at http://www.eclipse.org.

27 | 28 | 29 | -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_SRCDIRS=MQTTClient-C/src MQTTPacket/src MQTTClient-C/src/linux 2 | COMPONENT_ADD_INCLUDEDIRS=MQTTClient-C/src MQTTPacket/src MQTTClient-C/src/linux -------------------------------------------------------------------------------- /networking/mqtt/paho_mqtt_embedded_c/edl-v10: -------------------------------------------------------------------------------- 1 | 2 | Eclipse Distribution License - v 1.0 3 | 4 | Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. 5 | 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 9 | 10 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 12 | Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | 16 | -------------------------------------------------------------------------------- /networking/telnet/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | components/ 4 | -------------------------------------------------------------------------------- /networking/telnet/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := app-template 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /networking/telnet/README.md: -------------------------------------------------------------------------------- 1 | #Telnet 2 | This sample illustrates the use of the libtelnet library that can be 3 | read about here: 4 | 5 | [https://github.com/seanmiddleditch/libtelnet](https://github.com/seanmiddleditch/libtelnet) 6 | 7 | The sample connects to a WiFi access point and then starts to listen on 8 | TCP port 23 (Telnet) for an incoming client request. 9 | 10 | ##Addition of libtelnet 11 | To install the libtelnet component: 12 | 13 | 1. Create a sub-directory called `components`. 14 | 2. Change into `components`. 15 | 3. Clone the libtelnet repository: 16 | ``` 17 | $ git clone https://github.com/seanmiddleditch/libtelnet.git 18 | ``` 19 | 4. Change into `libtelnet` 20 | 5. Create a directory called `include`. 21 | 6. Copy all the `*.h` files into `include`: 22 | ``` 23 | $ cp *.h include/ 24 | ``` 25 | 7. Create a `component.mk` file that contains: 26 | ``` 27 | include $(IDF_PATH)/make/component_common.mk 28 | ``` -------------------------------------------------------------------------------- /networking/telnet/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | COMPONENT_ADD_INCLUDEDIRS=. 10 | include $(IDF_PATH)/make/component_common.mk 11 | -------------------------------------------------------------------------------- /networking/telnet/main/telnet.h: -------------------------------------------------------------------------------- 1 | void telnet_esp32_listenForClients(void (*callbackParam)(uint8_t *buffer, size_t size)); 2 | void telnet_esp32_sendData(uint8_t *buffer, size_t size); 3 | int telnet_esp32_vprintf(const char *fmt, va_list va); 4 | -------------------------------------------------------------------------------- /nvs/fragments/errorToString.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkolban/esp32-snippets/fe3d318acddf87c6918944f24e8b899d63c816dd/nvs/fragments/errorToString.c -------------------------------------------------------------------------------- /partitions/fragments/partitionSubtypeToString.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const char *partitionSubtypeToString(esp_partition_subtype_t subtype) { 4 | switch(subtype) { 5 | case ESP_PARTITION_SUBTYPE_APP_FACTORY: 6 | return "APP_FACTORY"; 7 | case ESP_PARTITION_SUBTYPE_APP_OTA_0: 8 | return "APP_OTA_0"; 9 | case ESP_PARTITION_SUBTYPE_APP_OTA_1: 10 | return "APP_OTA_1"; 11 | case ESP_PARTITION_SUBTYPE_APP_OTA_10: 12 | return "APP_OTA_10"; 13 | case ESP_PARTITION_SUBTYPE_APP_OTA_11: 14 | return "APP_OTA_11"; 15 | case ESP_PARTITION_SUBTYPE_APP_OTA_12: 16 | return "APP_OTA_12"; 17 | case ESP_PARTITION_SUBTYPE_APP_OTA_13: 18 | return "APP_OTA_13"; 19 | case ESP_PARTITION_SUBTYPE_APP_OTA_14: 20 | return "APP_OTA_14"; 21 | case ESP_PARTITION_SUBTYPE_APP_OTA_15: 22 | return "APP_OTA_15"; 23 | case ESP_PARTITION_SUBTYPE_APP_OTA_2: 24 | return "APP_OTA_2"; 25 | case ESP_PARTITION_SUBTYPE_APP_OTA_3: 26 | return "APP_OTA_3"; 27 | case ESP_PARTITION_SUBTYPE_APP_OTA_4: 28 | return "APP_OTA_4"; 29 | case ESP_PARTITION_SUBTYPE_APP_OTA_5: 30 | return "APP_OTA_5"; 31 | case ESP_PARTITION_SUBTYPE_APP_OTA_6: 32 | return "APP_OTA_6"; 33 | case ESP_PARTITION_SUBTYPE_APP_OTA_7: 34 | return "APP_OTA_7"; 35 | case ESP_PARTITION_SUBTYPE_APP_OTA_8: 36 | return "APP_OTA_8"; 37 | case ESP_PARTITION_SUBTYPE_APP_OTA_9: 38 | return "APP_OTA_9"; 39 | case ESP_PARTITION_SUBTYPE_APP_TEST: 40 | return "APP_TEST"; 41 | case ESP_PARTITION_SUBTYPE_DATA_ESPHTTPD: 42 | return "DATA_ESPHTTPD"; 43 | case ESP_PARTITION_SUBTYPE_DATA_FAT: 44 | return "DATA_FAT"; 45 | case ESP_PARTITION_SUBTYPE_DATA_NVS: 46 | return "DATA_NVS"; 47 | case ESP_PARTITION_SUBTYPE_DATA_OTA: 48 | return "DATA_OTA"; 49 | case ESP_PARTITION_SUBTYPE_DATA_PHY: 50 | return "DATA_PHY"; 51 | case ESP_PARTITION_SUBTYPE_DATA_SPIFFS: 52 | return "DATA_SPIFFS"; 53 | default: 54 | return "Unknown"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /partitions/fragments/partitionTypeToString.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const char *partitionTypeToString(esp_partition_type_t type) { 4 | switch(type) { 5 | case ESP_PARTITION_TYPE_APP: 6 | return "APP"; 7 | case ESP_PARTITION_TYPE_DATA: 8 | return "DATA"; 9 | default: 10 | return "Unknown"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /posix/README.md: -------------------------------------------------------------------------------- 1 | # POSIX 2 | Posix is the specification for Unix like functions. The ESP-IDF provides many implementations for Posix functions but some are omitted and thus should not be used in ESP32 based applications. However there are times when we received 3rd party code that uses a Posix function that we don't have in our environment. Our choices then become: 3 | 4 | * Contact the 3rd party provider and ask them to alter their code to remove it, replace it or make it optional. 5 | * Contact Espressif and ask them to add support for the missing Posix function. 6 | * Provide a shim that satisfies the Posix function using the capabailities that are available to us. 7 | 8 | In the source file called `posix_shims.c` we provide some of those shims. -------------------------------------------------------------------------------- /posix/posix_shims.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * @brief Provide a shim for the Posix access(2) function. 7 | * @param [in] pathname The file to check. 8 | * @param [in] mode The mode of access requested. 9 | * @return 0 on success, -1 on error with errno set. 10 | */ 11 | int access(const char *pathname, int mode) { 12 | struct stat statBuf; 13 | if (stat(pathname, &statBuf) == -1) { 14 | errno = ENOENT; 15 | return -1; 16 | } 17 | return 0; // Indicate that all we have access to the file. 18 | } // access 19 | -------------------------------------------------------------------------------- /pwm/README.md: -------------------------------------------------------------------------------- 1 | ### See also 2 | * hardware/servos -------------------------------------------------------------------------------- /rmt/README.md: -------------------------------------------------------------------------------- 1 | ### See also 2 | * hardware/neopixels 3 | * hardware/infrared -------------------------------------------------------------------------------- /skeletons/cpp/README.md: -------------------------------------------------------------------------------- 1 | # C++ Skeletons 2 | This directory contains some skeletons for main files for C++ applications. 3 | 4 | * `main_helloworld.cpp` - Simple main startup. 5 | * `main_network.cpp` - Simple main with networking via WiFi. -------------------------------------------------------------------------------- /skeletons/cpp/main_helloworld.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 1. Open up the project properties 3 | * 2. Visit C/C++ General > Preprocessor Include Paths, Macros, etc 4 | * 3. Select the Providers tab 5 | * 4. Check the box for "CDT GCC Built-in Compiler Settings" 6 | * 5. Set the compiler spec command to "xtensa-esp32-elf-gcc ${FLAGS} -E -P -v -dD "${INPUTS}"" 7 | * 6. Rebuild the index 8 | */ 9 | 10 | #include 11 | #include 12 | #include "sdkconfig.h" 13 | 14 | 15 | static char tag[]="cpp_helloworld"; 16 | 17 | extern "C" { 18 | void app_main(void); 19 | } 20 | 21 | class Greeting { 22 | public: 23 | void helloEnglish() { 24 | ESP_LOGD(tag, "Hello %s", name.c_str()); 25 | } 26 | 27 | void helloFrench() { 28 | ESP_LOGD(tag, "Bonjour %s", name.c_str()); 29 | } 30 | 31 | void setName(std::string name) { 32 | this->name = name; 33 | } 34 | private: 35 | std::string name = ""; 36 | 37 | }; 38 | 39 | void app_main(void) 40 | { 41 | Greeting myGreeting; 42 | myGreeting.setName("Neil"); 43 | myGreeting.helloEnglish(); 44 | myGreeting.helloFrench(); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /skeletons/cpp/main_network.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "sdkconfig.h" 7 | 8 | static char tag[] = "my tag"; 9 | extern "C" { 10 | void app_main(void); 11 | } 12 | 13 | class MyWiFiEventHandler: public WiFiEventHandler { 14 | 15 | esp_err_t staGotIp(system_event_sta_got_ip_t event_sta_got_ip) { 16 | ESP_LOGD(tag, "MyWiFiEventHandler(Class): staGotIp"); 17 | // Do something 18 | return ESP_OK; 19 | } 20 | }; 21 | 22 | void app_main(void) 23 | { 24 | WiFi wifi; 25 | MyWiFiEventHandler *eventHandler = new MyWiFiEventHandler(); 26 | 27 | wifi.setWifiEventHandler(eventHandler); 28 | wifi.setIPInfo("192.168.1.99", "192.168.1.1", "255.255.255.0"); 29 | wifi.connectAP("myssid", "mypassword"); 30 | } 31 | -------------------------------------------------------------------------------- /sntp/fragments/sntp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "sdkconfig.h" 9 | 10 | /* 11 | * Connect to an Internet time server to get the current date and 12 | * time. 13 | */ 14 | void startSNTP() { 15 | ip_addr_t addr; 16 | sntp_setoperatingmode(SNTP_OPMODE_POLL); 17 | inet_pton(AF_INET, "129.6.15.28", &addr); 18 | sntp_setserver(0, &addr); 19 | sntp_init(); 20 | } 21 | -------------------------------------------------------------------------------- /sockets/client/socketClient.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sdkconfig.h" 8 | 9 | static char tag[] = "socketClient"; 10 | 11 | void socketClient(void *ignore) { 12 | ESP_LOGD(tag, "start"); 13 | int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 14 | 15 | ESP_LOGD(tag, "socket: rc: %d", sock); 16 | struct sockaddr_in serverAddress; 17 | serverAddress.sin_family = AF_INET; 18 | inet_pton(AF_INET, "192.168.1.200", &serverAddress.sin_addr.s_addr); 19 | serverAddress.sin_port = htons(9999); 20 | 21 | int rc = connect(sock, (struct sockaddr *)&serverAddress, sizeof(struct sockaddr_in)); 22 | ESP_LOGD(tag, "connect rc: %d", rc); 23 | 24 | char *data = "Hello world"; 25 | rc = send(sock, data, strlen(data), 0); 26 | ESP_LOGD(tag, "send: rc: %d", rc); 27 | 28 | rc = close(sock); 29 | ESP_LOGD(tag, "close: rc: %d", rc); 30 | 31 | vTaskDelete(NULL); 32 | } 33 | -------------------------------------------------------------------------------- /sockets/utilities/socket_utils.c: -------------------------------------------------------------------------------- 1 | #include "lwip/socket.h" 2 | 3 | static void dumpSockaddr(struct sockaddr_in address) { 4 | ESP_LOGD(tag, "Address details:"); 5 | char *family = "Unknown"; 6 | unsigned short port; 7 | char ipString[20]; 8 | 9 | if (address.sin_family == AF_INET) { 10 | family = "AF_INET"; 11 | } else if (address.sin_family == AF_INET6) { 12 | family = "AF_INET6"; 13 | } 14 | port = ntohs(address.sin_port); 15 | inet_ntop(address.sin_family, &address.sin_addr, ipString, sizeof(ipString)) ; 16 | ESP_LOGD(tag, "Address details: family=%s, ip=%s, port=%d", family, ipString, port); 17 | } 18 | -------------------------------------------------------------------------------- /tasks/watchdogs/README.md: -------------------------------------------------------------------------------- 1 | # Watchdogs 2 | This is a sample application that illustrates the capabilities of watchdogs and watchdog processing. 3 | 4 | A related YouTube video is available here: 5 | 6 | https://www.youtube.com/watch?v=C2xF3O6qkbg -------------------------------------------------------------------------------- /tools/bootloaderExamine/.gitignore: -------------------------------------------------------------------------------- 1 | /a.out 2 | /app-template.bin 3 | -------------------------------------------------------------------------------- /tools/esptool_libs/README.md: -------------------------------------------------------------------------------- 1 | # Esptool libraries 2 | The Espressif awesome esptool performs just about anything you may want to do relating to ESP32 programming over UART. It can write to flash, write to memory, erase flash and a world of other features. The specification of the protocol can be found in the `esptool` github project Wiki. 3 | 4 | This section of this repository hosts libraries for working with this protocol. There is an implementation in Node.js and more to come including C and C++. -------------------------------------------------------------------------------- /tools/esptool_libs/nodejs/README.md: -------------------------------------------------------------------------------- 1 | # NodeJS ESP Tools 2 | 3 | The `build.js` tool is used to take the `stub_flasher_32.elf` and break it apart into the separate files that need to be individually pushed to ESP32 RAM for execution. -------------------------------------------------------------------------------- /tools/esptool_libs/nodejs/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Extract the text and data sections to their own files. 3 | xtensa-esp32-elf-objcopy \ 4 | --dump-section .text=text.dat \ 5 | --dump-section .data=data.dat \ 6 | stub_flasher_32.elf 7 | 8 | # Parse out the text load address, the data load address and the entry point from the ELF. 9 | text_address=`xtensa-esp32-elf-objdump --section-headers --wide --section=.text stub_flasher_32.elf | sed -n '$s/^\s*[[:alnum:]]*\s*\S*\s*[[:alnum:]]*\s*[[:alnum:]]*\s*\([[:alnum:]]*\).*/\1/p'` 10 | #echo "Text address: 0x${text_address}" 11 | data_address=`xtensa-esp32-elf-objdump --section-headers --wide --section=.data stub_flasher_32.elf | sed -n '$s/^\s*[[:alnum:]]*\s*\S*\s*[[:alnum:]]*\s*[[:alnum:]]*\s*\([[:alnum:]]*\).*/\1/p'` 12 | #echo "Data address: 0x${data_address}" 13 | entry_point=`xtensa-esp32-elf-objdump --wide --file-headers stub_flasher_32.elf | sed -n '/start address/s/start address 0x\([[:alnum:]]\)/\1/p'` 14 | #echo "Entry point: 0x${entry_point}" 15 | 16 | echo "{" 17 | echo " \"textAddress\": \"${text_address}\"," 18 | echo " \"dataAddress\": \"${data_address}\"," 19 | echo " \"entryPoint\": \"${entry_point}\"," 20 | echo " \"textData\": \"$(base64 --wrap=0 text.dat)\"," 21 | echo " \"dataData\": \"$(base64 --wrap=0 data.dat)\"" 22 | echo "}" 23 | 24 | # Remove the temporary text and data files. 25 | #rm text.dat data.dat 26 | -------------------------------------------------------------------------------- /tools/sdkconfig_compare/README.md: -------------------------------------------------------------------------------- 1 | This is a node.js application which takes as input two files. Each file should be an ESP-IDF `sdkconfig` file. The tool compares the two files and logs the logical distinctions between them. For example, if one file has an entry while the other doesn't, that will be logged. If one file has an entry with a value that is different from the other, that too will be logged. -------------------------------------------------------------------------------- /uart/readLine.c: -------------------------------------------------------------------------------- 1 | #include "driver/uart.h" 2 | 3 | char *readLine(uart_port_t uart) { 4 | static char line[256]; 5 | int size; 6 | char *ptr = line; 7 | while(1) { 8 | size = uart_read_bytes(UART_NUM_1, (unsigned char *)ptr, 1, portMAX_DELAY); 9 | if (size == 1) { 10 | if (*ptr == '\n') { 11 | *ptr = 0; 12 | return line; 13 | } 14 | ptr++; 15 | } // End of read a character 16 | } // End of loop 17 | } // End of readLine 18 | -------------------------------------------------------------------------------- /vfs/spiffs/spiffs_vfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * spiffs_vfs.h 3 | * 4 | * Created on: Dec 3, 2016 5 | * Author: kolban 6 | */ 7 | 8 | #ifndef MAIN_SPIFFS_VFS_H_ 9 | #define MAIN_SPIFFS_VFS_H_ 10 | #include "spiffs.h" 11 | void spiffs_registerVFS(char *mountPoint, spiffs *fs); 12 | 13 | 14 | #endif /* MAIN_SPIFFS_VFS_H_ */ 15 | -------------------------------------------------------------------------------- /vfs/vfs-skeleton/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | -------------------------------------------------------------------------------- /vfs/vfs-skeleton/README.md: -------------------------------------------------------------------------------- 1 | #VFS 2 | 3 | -------------------------------------------------------------------------------- /vfs/vfs-skeleton/main/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Test the Virtual File System 3 | * 4 | * Perform a test against the Virtual File System. 5 | * 6 | * For additional details and documentation see: 7 | * * Free book on ESP32 - https://leanpub.com/kolban-ESP32 8 | * 9 | * 10 | * Neil Kolban 11 | * 12 | */ 13 | #include "freertos/FreeRTOS.h" 14 | #include "esp_wifi.h" 15 | #include "esp_system.h" 16 | #include "esp_event.h" 17 | #include "esp_event_loop.h" 18 | #include "esp_log.h" 19 | #include "nvs_flash.h" 20 | #include "driver/gpio.h" 21 | #include "vfsTest.h" 22 | #include "stdio.h" 23 | #include "fcntl.h" 24 | 25 | char tag[] = "vfs-skeleton"; 26 | esp_err_t wifi_event_handler(void *ctx, system_event_t *event) 27 | { 28 | return ESP_OK; 29 | } 30 | 31 | int app_main(void) 32 | { 33 | nvs_flash_init(); 34 | system_init(); 35 | tcpip_adapter_init(); 36 | ESP_ERROR_CHECK( esp_event_loop_init(wifi_event_handler, NULL) ); 37 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); 38 | ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); 39 | ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); 40 | ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); 41 | wifi_config_t sta_config = { 42 | .sta = { 43 | .ssid = "access_point_name", 44 | .password = "password", 45 | .bssid_set = false 46 | } 47 | }; 48 | ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) ); 49 | //ESP_ERROR_CHECK( esp_wifi_start() ); 50 | //ESP_ERROR_CHECK( esp_wifi_connect() ); 51 | 52 | // Perform the tests on the VFS 53 | registerTestVFS("/data"); 54 | ESP_LOGI(tag, "vfs registered"); 55 | 56 | FILE *file = fopen("/data/x", "w"); 57 | if (file == NULL) { 58 | ESP_LOGE(tag, "failed to open file"); 59 | return 0; 60 | } 61 | 62 | fprintf(file, "Hello!"); 63 | return 0; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /vfs/vfs-skeleton/main/vfsTest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Test the Virtual File System 3 | * 4 | * Perform a test against the Virtual File System. 5 | * 6 | * For additional details and documentation see: 7 | * * Free book on ESP32 - https://leanpub.com/kolban-ESP32 8 | * 9 | * 10 | * Neil Kolban 11 | * 12 | */ 13 | 14 | #ifndef MAIN_VFSTEST_H_ 15 | #define MAIN_VFSTEST_H_ 16 | 17 | void registerTestVFS(char *mountPoint); 18 | 19 | #endif /* MAIN_VFSTEST_H_ */ 20 | -------------------------------------------------------------------------------- /wifi/fragments/auth_mode_to_string.c: -------------------------------------------------------------------------------- 1 | char *authModeToString(wifi_auth_mode_t mode) { 2 | switch(mode) { 3 | case WIFI_AUTH_OPEN: 4 | return "open"; 5 | case WIFI_AUTH_WEP: 6 | return "wep"; 7 | case WIFI_AUTH_WPA_PSK: 8 | return "wpa"; 9 | case WIFI_AUTH_WPA2_PSK: 10 | return "wpa2"; 11 | case WIFI_AUTH_WPA_WPA2_PSK: 12 | return "wpa_wpa2"; 13 | default: 14 | return "unknown"; 15 | } 16 | } 17 | --------------------------------------------------------------------------------