ESP32 OTA Updates over BLE from a React Web Application
The ESP32 is a ridiculously capable microcontroller. With WiFi, Bluetooth, and two cores, there's a ton you can do with it including update the firmware without ever plugging it into your computer. This is something I've been wanting to implement for a while to allow somebody like my grandmother to push software updates to a hypothetical electronic gift. The examples I kept seeing on the internet were all based on the ArduinoOTA examples included in the Arduino IDE, and followed the same basic method.
- Hardcode your SSID and Password into the ESP32 using the Arduino IDE
- Connect the ESP32 to WiFi and have it set up a local web server capable of receiving a binary file.
- Obtain the IP address over serial if ESP32's mDNS doesn't want to work on your network.
- Have the compiled binary stored locally on your computer or phone.
- Navigate to the page or IP address of the ESP32
- Browse to the file using the dropdown provided by the ESP32 and hit send.
This process functions well and updates the ESP32 in a few seconds depending on file size, but for some applications, it isn't the best. For example, I wanted a nice clunky application in the HTML as well that could interact with my ESP32 over BLE, and putting that into the Arduino sketch (In addition to being difficult to deal with) would probably exceed the memory budget for OTA updates anyway. So, since I'm already using BLE and a webapp, let's toss OTA updates in as the icing on the cake. BLE isn't the best way to do this, but like I said, it's already in use elsewhere. This BLE OTA update employs the following method.
- ESP32 begins BLE server.
- WebApp allows the user to pair with our ESP32 BLE Server using Web Bluetooth. (Sorry iPhone users)
- Upon pairing, the WebApp reads the hardware and software version numbers hard-coded into the sketch on the ESP32.
- This version number is crosschecked with a JSON file of containing software versions along with their compatible hardware versions.
- If a compatible update is available, the user is asked if they want to update.
- If the user clicks yes, the WebApp fetches the firmware and writes it to the ESP32 in buffered chunks.