This micropython module allows for automatic updating of your code on Microcontrollers using github releases. It allows you to update devices in the field with ease.
Note: due to a bug in the SSL library of ESP8266 devices, micropython-ota-updater cannot be used on these devices. See https://github.com/rdehuyss/micropython-ota-updater/issues/6 and https://github.com/micropython/micropython/issues/6737
The workflow is as follows:
app
)There are now two different ways to update your code:
You can choose to install a new version yourself. Note that due to memory limitations, this must happen first thing after boot.
To do so, make sure you have an active internet connection and use the following code at startup:
@staticmethod
def _otaUpdate():
ulogging.info('Checking for Updates...')
from .ota_updater import OTAUpdater
otaUpdater = OTAUpdater('https://github.com/rdehuyss/chicken-shed-mgr', github_src_dir='src', main_dir='app', secrets_file="secrets.py")
otaUpdater.install_update_if_available()
del(otaUpdater)
Do not forget to do a machine.reset() after the code above.
ota_updater.check_for_update_to_install_during_next_reboot()
next
folder and within that folder a file called .version_on_reboot
. After that, you do a machine.reset()
to kill the WIFI connection.You use the following code in your main.py
:
from ota_update.main.ota_updater import OTAUpdater
def download_and_install_update_if_available():
o = OTAUpdater('url-to-your-github-project')
o.install_update_if_available_after_boot('wifi-ssid', 'wifi-password')
def start():
# your custom code goes here. Something like this: ...
# from main.x import YourProject
# project = YourProject()
# ...
def boot():
download_and_install_update_if_available()
start()
boot()
next/.version_on_reboot
.
app
folder. You then need to do a machine.reset()
. On reboot, the latest code will be in the app
folder and you will be running the latest version.app
folderThis module also adds support for private repositories. To do so, use it as follows:
token='YOUR_GITHUB_TOKEN'
updater = OTAUpdater('https://github.com/sergiuszm/cae_fipy', headers={'Authorization': 'token {}'.format(token)})
MicroPython OTA updater now also supports a secret file (which is added to .gitignore). This secrets file must be installed initially (e.g. using USB) and will always be kept when downloading newer versions. In my case, it contains the WIFI credentials and other secret stuff. A secrets file can be used as follows:
WIFI_SSID='your-ssid'
WIFI_PASSWORD='your-password'
See main.py on how it is then used.
See the article on Medium.