MostlyHarmless wrote: ↑Wed Dec 04, 2019 9:55 pm
It will help to divide the code into "stable" and "volatile" modules. The stable parts would be deployed as frozen modules (hard to update), the volatile parts would be precompiled .mpy file (slightly easier to update).
I'd thought about something like that, too.
kevinkk525 wrote: ↑Thu Dec 05, 2019 6:19 am
The problem is that you also need some OTA mechanism, even if only by webrepl. This mechanism takes RAM as well...
My current solution will go into separate code branches in
main.py between
OTA code <-> web server code
See:
Code: Select all
if rtc.d.get(_RTC_KEY_RUN) == _RUN_WEB_SERVER:
print('start webserver')
rtc.save(data={_RTC_KEY_RUN: _RUN_OTA_UPDATE}) # next boot -> start OTA
from webswitch import WebServer
from watchdog import Watchdog
from power_timer import AutomaticTimer
gc.collect()
WebServer(
pins=pins, rtc=rtc,
watchdog=Watchdog(wifi=wifi, rtc=rtc, auto_timer=AutomaticTimer(rtc=rtc, pins=pins)),
version=__version__
).run()
else:
print('start OTA')
rtc.save(data={_RTC_KEY_RUN: _RUN_WEB_SERVER}) # next boot -> start web server
from ota_client import OtaUpdate
gc.collect()
OtaUpdate().run()
That's why every code part has the full RAM available.
kevinkk525 wrote: ↑Thu Dec 05, 2019 6:19 am
With the recent addition of LittleFS on Esp8266 you can now get 4kB of RAM additionally if you format your filesystem with littlefs. This could make enough RAM available for such a mechanism and using a few more .mpy files.
Thanks, that's great. 4kB is a lot. It's worth it. I didn't know that
littlefs existed yet.
kevinkk525 wrote: ↑Thu Dec 05, 2019 6:19 am
But if someone is really worried about not being able to update a device often enough and has not enough RAM available, I'd recommend using the ESP32. It might be twice the cost of an esp8266 but is still very cheap and the higher RAM makes it easy to only use .mpy files and some OTA mechanism or ftp server.
I have some ESP32 devices here. e.g. also the
OdroidGo. But I don't have a useful job for it, except to experiment with micropython
But it's more practical to have "ready-made" devices that can really do something. That's why I used the
Sonoff WiFi Smart Socket.
I opened a separate thread. With the question which end-user devices have an ESP32:
viewtopic.php?f=2&t=7352