OTA Firmware Updates ?!?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

OTA Firmware Updates ?!?

Post by jedie » Mon Nov 25, 2019 7:22 pm

Is there a common way to make OTA Updates?

A first step would be to update only the script files. I think I could implement it myself. But what about a real firmware update to update micropython itself? Is there such a feature already in any project?

EDIT: I should take a look into: https://github.com/rdehuyss/micropython-ota-updater

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: OTA Firmware Updates ?!?

Post by cgglzpy » Tue Nov 26, 2019 3:44 pm

Hi jedie,

To update script files there are some alternatives (as far as I know):
- FTP Server (from @Roberthh): https://github.com/robert-hh/FTP-Server ... 2-and-PYBD
- uPyLoader (from @Beta_Ravener): https://github.com/BetaRavener/uPyLoader/
- webrepl_cli.py (from micropython/webrepl repo) : https://github.com/micropython/webrepl/ ... epl_cli.py
- http://micropython.org/webrepl/

I'm also working on upydev based on webrepl_cli.py. It's a CLI tool that allows (among other things) to upload scripts/files (one or multiple files) and more recently to recursively sync entire directories.
And it can be easily integrated with Atom or VSC editors. (see https://github.com/Carglglz/upydev/blob ... .md#how-to)

For the firmware update I know there is a work-in-progress (at least for the esp8266). You can see it at http://micropython.org/download
The following are Over-The-Air (OTA) builds of the ESP8266 firmware, for modules with at least 1MByte of flash. The first time you use this build you need to flash one of the "initial image" images using esptool.py as described above. After that, you can update the firmware over the air using the "OTA update" file in conjunction with the ota-client script from yaota8266. The "OTA update" files are digitally signed and will only work with the provided "initial image" files, and vice versa. (Note: this feature is work-in-progress.)

jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: OTA Firmware Updates ?!?

Post by jedie » Tue Nov 26, 2019 5:18 pm

Oh, cool, thanks.

I didn't find the OTA build. They are a bit hidden on the long page ;) They used https://github.com/pfalcon/yaota8266 but this project seems to be unmaintained: last commit is 3 years old :(

https://github.com/Carglglz/upydev look interesting, but the target group are probably more developers than end users and WebREPL file transfer has known issues on ESP8266: https://github.com/micropython/webrepl# ... e-transfer

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: OTA Firmware Updates ?!?

Post by cgglzpy » Tue Nov 26, 2019 6:14 pm

They used https://github.com/pfalcon/yaota8266 but this project seems to be unmaintained: last commit is 3 years old :(
Yes I know, but maybe it could be a starting point :roll:
WebREPL file transfer has known issues on ESP8266: https://github.com/micropython/webrepl# ... e-transfer
So far I've been using it and it's reliable enough to work with. The only "issues" I've found are:

- The name of the file + absolute path can't be longer than 64 characters (it won't raise any error if longer but the name will be cut at 64)
- The transfer speed when getting files from the device is quite slow so it should be used for small files only.

For both issues there are workarounds (that are already included in upydev) so they are not a big deal.
look interesting, but the target group are probably more developers than end users
Yes the target group are developers (although I try to include all the info/examples I can to make it quite easy to use),
Again this and the other tools I've listed could be a starting point (or just get some ideas) if you plan to implement something yourself. :)

jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: OTA Firmware Updates ?!?

Post by jedie » Fri Nov 29, 2019 7:51 am

I started a own implementation of OTA updates of own scripts.

OTA Server for the host: https://github.com/jedie/micropython-so ... _server.py
OTA Client for the device: https://github.com/jedie/micropython-so ... _client.py

It doesn't always work, though. Because there is not enough RAM, but only sometimes.

There is room for improvement:
  • Discovery the server takes time.
  • The device should send information about his own files in a single step. That would make it much faster.
Maybe I'll turn it around: The device listens on a port and the host searches for the device. That probably makes it easier.


I have tried https://github.com/rdehuyss/micropython-ota-updater too. That would be good for end users. But I get RAM full all the time. Think the github api json data are just to big.

jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: OTA Firmware Updates ?!?

Post by jedie » Sun Dec 01, 2019 11:51 am

I refactor the OTA code (WIP):

host part: https://github.com/jedie/micropython-so ... _server.py
device part: https://github.com/jedie/micropython-so ... _client.py

Any idea how to optimize this?!? Any suggestions?

EDIT: I switched the connection: The Device listen on port 8266 and the host scans the network and connects to the device. So i have less code on the device and the host scan is faster.

Next ideas or TODOs:
  • The device listen with timeout (e.g.: 30sec) and boots the real code if no connection came in.
  • The OTA device code ends always with a reset: Store OTA success/fail into RTC RAM
  • Skip OTA on boot if it was done before (Maybe if last OTA was done in last 1hour or so)

jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: OTA Firmware Updates ?!?

Post by jedie » Mon Dec 02, 2019 11:43 am

I'm done and it works good:

Host part -> https://github.com/jedie/micropython-so ... _server.py
Device part -> https://github.com/jedie/micropython-so ... _client.py

Currently i implement it as follows:

The device always boots alternating: "make OTA" <-> "Start web server" via main.py
I store in RTC RAM which part is active, they toggle on every start.
The OTA part waits 30sec for a connection and will always call in the end: machine.reset()
This means that Web Server and OTA parts have all the RAM for themselves ;)

This is also not really enduser friendly. But what the hell :mrgreen:

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: OTA Firmware Updates ?!?

Post by cgglzpy » Thu Dec 05, 2019 4:42 pm

Hi and yes
This is also not really enduser friendly. But what the hell :mrgreen:
I think starting the OTA from the command line is not "really enduser friendly" as you were asking for.

To make it really enduser friendly the "OTA updater" should have a GUI I guess... :roll:

jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: OTA Firmware Updates ?!?

Post by jedie » Thu Dec 05, 2019 5:09 pm

cgglzpy wrote:
Thu Dec 05, 2019 4:42 pm
To make it really enduser friendly the "OTA updater" should have a GUI I guess... :roll:
A simple TK GUI is quickly made.
But then we come to the bigger problem: How to offer an end-user GUI program written in Python?

Actually, it's just: git clone and pipenv run gui

Well, let's see ;)

User avatar
MostlyHarmless
Posts: 166
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: OTA Firmware Updates ?!?

Post by MostlyHarmless » Thu Dec 05, 2019 7:20 pm

jedie wrote:
Thu Dec 05, 2019 5:09 pm
But then we come to the bigger problem: How to offer an end-user GUI program written in Python?
There is pyqt4 and designer-qt4 to write GUI programs in Python. Haven't used those in a while, but it wasn't too difficult to get started with that. Not volunteering here, just saying.


Regards, Jan

Post Reply