Monday, May 29, 2017

- IoT (Internet of Things) means many devices connect to the Internet. If there is bug in the software of devices, the process to fix bug and re-flash the software will cost much effort, time and money. That is why people use FOTA (firmware update over the air) for IoT devices. You do not need to unplug the device from the network and use hardware flashing tool to re-flash software for it. Everything happens over the air, just create the wireless connection to the device and transfer the software to it chunk by chunk. The device will receive the chunk and write it to a specific address in Flash. After finishing flashing, the device will reboot and run the new software. It is similar to update software for your mobile over the WiFi/3G.

- We will create a demo for FOTA, first we flash the firmware with FOTA functionality and LED blinky on pin GPIO12 by normal way (USB-TTL port). Then we update the firmware with FOTA functionality but LED blinky on pin GPIO14 by FOTA way.

2. Hardware

We connect 2 LEDs on GPIO12 and GPIO14. After first flashing, LED on GPIO12 will blink. But after second flashing, LED on GPIO14 will blink.

3. Software

- Arduino ESP32 core supplied ArduinoOTA library for us to use FOTA functionality. So we just include "ArduinoOTA.h". I will explain the code by the comments in code, so you just read it.
Note: FOTA functionality will use use 2 TCP/Ip connections. First connection is to communicate with ESP32 to control flashing work flow. Second connection is to transfer the firmware chunk by chunk.
- Create an Arduino project with code below, save as esp32otafw1 and flash it to ESP32 by normal way:

- In order to transfer the new firmware to ESP32 OTA we will use a python tool called "espota.py" in "where_you_install_Arduino/Arduino/hardware/espressif/esp32/tools"
This tool has arguments:"python espota.py -i ESP_IP_address -I Host_IP_address -p ESP_port -P Host_port [-a password] -f sketch.bin"Note: in order to get "sketch.bin", from Arduino menu bar, choose Sketch - Export Compiled Binaryand then from Arduino menu bar, choose Sketch - Show Sketch Folder - you will see a ".bin" file there. So get the absolute path to this ".bin" file for later usage.
- In order to update for multiple ESP32 clients I created a small Python script "espotabatch.py", you just change a little bit to adapt your need. This script will be put in the same folder with "espota.py"