Page 1 of 1

clone firmware between ESP32 in a Mesh network OTA

Posted: Mon Sep 14, 2020 3:38 pm
by Esp32_IoTer
I am not sure if this is the correct section to post this question, but I am working with ESP32 painlessmesh. I developed a mesh newtork between several devices. They do not have any internet access, but they send/receive short messages to the outside world when a phone is connected via ble (by means of an APP I developed) to one of the device. The simple information is the status of the device, on/off and so on.

My question is: let's assume I want to update the firmware of this device (they all run the same firmware). I can tell the app to check online for a new firmware and send it OTA for example via ble (I know it's not the best method, but it works... since I don't want the user of the app to connect to the wifi of the network and so on...) to the specific node to which is connected. Now, is there a way this updated node can "clone" itself and send via OTA the updated firmware to all the nodes connected to the mesh network? Is it possible for an ESP32 to send its own firmware to another ESP32?

Thank you =).

Re: clone firmware between ESP32 in a Mesh network OTA

Posted: Sat Sep 19, 2020 11:25 am
by StefanRvO
I'm using ESP Mesh, but i have done something similair.

My basic approach is:

- All nodes (root and slaves) compute a sha256 sum of their currently active firmware partition.

- The slaves repeatedly sends their sha256 to the root node, as well as how much of the root nodes firmware they have received.

- If the root node receives a message with a sha that doesn't match its own, it starts broadcasting pieces of its firmware to the slaves. As there is no delivery guarantee in my network, the root node keeps track of which pieces of the firmware the slaves report that they have still not received, and resends them if necessary. If a new slave connects during the update it will send that it having received any chunks yet, which will make the root node start over. Included in the firmware chunks is the root nodes sha

- The slave nodes keeps track of received pieces and write them to the next ota partition if the root nodes sha is different from its own.

- When a slave node determines it have written all the pieces, it changes its boots partition and restarts.

If you do any breaking changes to the way this upgrade procedure is handled, you will need to flash all the nodes manually, as the root node can't upgrade them in that case.

My code is here: https://gitlab.com/StefanRvO/light-equa ... nc_lib.cpp https://gitlab.com/StefanRvO/light-equa ... module.cpp

It is probably somewhat specific to my application, but you may get some inspiration on how you can approach this.