Page 1 of 1

OTA of micropython code on ESP32?

Posted: Thu Oct 10, 2019 4:04 pm
by happyday
I am exploring "the best" way to do OTA of my micropython code that runs on an ESP32. Do you have any recommendations?

Thank you.

Re: OTA of micropython code on ESP32?

Posted: Wed Oct 16, 2019 4:47 am
by jimmo
Do you want to update the Python code or the actual firmware?

If it's the Python code, I'm not sure there's a "best" way...probably this is much more a question of how your application protocol works -- actually updating the files on the flash is pretty straightforward. You might definitely want to consider some sort of "safe mode" though -- i.e. never modify, and ensure that has enough logic to download new firmware.

Re: OTA of micropython code on ESP32?

Posted: Mon Dec 16, 2019 7:51 pm
by nebenzahl
Would you have any code that would download files from an FTP server?
I've been studying this for a long time and I can't move forward.


Re: OTA of micropython code on ESP32?

Posted: Mon Dec 16, 2019 7:59 pm
by jedie

Re: OTA of micropython code on ESP32?

Posted: Mon Dec 16, 2019 8:36 pm
by nebenzahl
Thanks, I saw this post.
However this is not what I am looking for, because there are file updates, downloading on github, also making an esp32 be an FTP server.
But what I only want is my ESP32 to download files from an FTP server on the internet, that's all.
That simple.
Does anyone have an example?

Re: OTA of micropython code on ESP32?

Posted: Fri Jan 24, 2020 1:57 pm
by BjHave
I'm also looking for an OTA update. There is some progress there, but not yet documented.

So far I managed to create a OTA supporting partition table.

Create your own board spec in the boards folder inside ports/esp32.

Like "GENERIC_OTA" for example.
Copy the mpconfigboard.h and the from another board e.g. GENERIC or add them to you folder.

In the mpconfigboard.h you could change the BoardName.

In the you could add a reference to your partition.csv (You can find an example in the GENERIC_D2WD/

Mine is looking like this:
SDKCONFIG += boards/sdkconfig.base
PART_SRC = partitions-ota.csv

My partitions-ota.csv file resides in the ports/esp32 folder and looks like this:
# Name, Type, SubType, Offset, Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs, data, nvs, 0x9000, 0x4000,
otadata, data, ota, 0xd000, 0x2000
phy_init, data, phy, 0xf000, 0x1000,
Mini_0, app, ota_0, , 1536K
Mini_1, app, ota_1, , 1536K,
vfs, data, fat, , 768K

I build my firmware with some modules so i needed some more space than 1MB the missing offsets are getting filled by esp partition tool.

That's all I've got so far.

On the first boot the partition table gets created. With :
from esp32 import Partition
you can access the different partitions as objects.
More on this here:

I'm struggling at the moment on how to get another firmware to the Mini_1 partition via download or copy. I'm fairly new to MCUs and (Micro)Python...

Once you managed to get the data to the other partition you can select it with the use of the Partition class and call part.set_boot() to mark this as active partition for the next boot.

If you or somebody else knows how to get the data to the other partition, please let me know.

Re: OTA of micropython code on ESP32?

Posted: Fri Jan 31, 2020 8:01 am
by BjHave
It was pretty straight forward to implement a PartitionCopy Method. I don't know if it is Pythonic ;) but I will share it:

Code: Select all

from esp32 import Partition
import gc

class Ota:
  SEC_SIZE = 4096
  def copyPartition(self):
    currentPartition = Partition(Partition.RUNNING)
    nextPartition = currentPartition.get_next_update()
    buf = bytearray(self.SEC_SIZE)
    for i in range(0,[3] // self.SEC_SIZE):
      currentPartition.readblocks(i, buf)
      nextPartition.writeblocks(i, buf)
      print('Block No. ' + str(i) + ' copied')
    print('Partition copied')