ESP32 is a feature-rich MCU with integrated Wi-Fi and Bluetooth connectivity for a wide-range of applications. For more information please go to ESP32 vendor website.
PoC was implemented to show ESP32-dev board capabilities. The application enables the following features:
1. UART data handling
2. SoftAP and STA WiFi
3. HTTP Server
4. MQTT client
5. OTA update functionality
1. Esp32-PoC application displays data received over UART on a console (one character a time)
> I (18957) UART: : Received: f
2. Esp32-PoC application setup WiFi to work in both modes (softAP and STA) simultaneously. As soon it receives SSID and password for AP it will connect to STA automatically.
> I (342) wifi: mode : sta (24:6f:28:de:79:94) + softAP (24:6f:28:de:79:95) > I (352) POC: wifi_init_ap_sta finished. ssid:TestAP password:nopassword
3. Esp32-PoC application starts HTTP server right after the client connects to softAP over WiFi.
> I (16282) POC: Starting server on address: port: '80'
Afterwards user can connect to HTTP server running on ESP32 board using the browser, as shown on the picture:
Here 192.168.4.1 is the ESP32-dev IP address. Every time user reloads the main page on 192.168.4.1 the Esp32-PoC application scans and returns the list of APs found.
There is a POST form in HTTP response and if user sends the SSID and password the Esp32-PoC application is trying to connect to that AP.
After connection to STA AP the HTTP server is not stopped and continues functioning giving the user a possibility to connect to another AP.
> softAP assign IP to station,IP is: 192.168.4.2 > I (26852) wifi: connected with PYUR C5A10, channel 1 > I (27712) event: sta ip: 192.168.0.6, mask: 255.255.255.0, gw: 192.168.0.1
4. As soon as esp32-poc application gets connected to STA AP it starts MQTT client which is connecting to a broker mqtts://iot.eclipse.org:8883.
CA certificate is embedded into Esp32-PoC binary and used afterwards in order to connect to the broker.
> I (44757) MQTT: : MQTT_EVENT_SUBSCRIBED, msg_id=62033
MQTT client subscribes on “ota_update” topic and waits until somebody notifies that there is a new Firmware available.
A special python script was implemented mqtt_test.py in order to publish messages on a channel which in turn trigger the OTA update on Esp32-PoC application.
> I (52437) OTA: : There is new OTA update! Connecting to OTA server....
5. When new OTA update notification is received Esp32-PoC application connects to HTTPS server and downloads the Firmware binary.
The self-signed CA certificate was embedded into the Esp32-PoC binary.
When the FW binary is downloaded Esp32-PoC application resets the board and boots from another partition.
> I (64367) esp_https_ota: Connection closed,all data received > I (65597) esp_https_ota: esp_ota_set_boot_partition succeeded > I (159) POC: POC version v0.2
- The Esp32-PoC image size: 726KB
- Free heap memory before OTA update run is 152Kb comparing to 276Kb when the app starts.
- Esp32-PoC uses 2 RootCA certificates to connect to SSL servers.
- Esp32-PoC runs HTTP server and softAP constantly allowing user to connect to STA AP.
Find logs in here.