Skip to content

smysnk/micropython-ota-updater

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MicroPython OTA Updater

Overview

Based off of rdehuyss's MicroPython OTA Updater. This MicroPython Over-The-Air Updater will follow a GitHub branch, checking for updates on boot. Will update if HEAD is not current (other release strategies may be added later).

Note: due to a bug in the SSL library of ESP8266 devices, micropython-ota-updater cannot be used on these devices. See rdehuyss#6 and micropython/micropython#6737

Gettings started

Edit src/env.py to fill in WiFi credentials, GitHub remote repository / branch and optional GitHub credentials to increase API limits (60 per hour to 5000). Deploy!

For an example implementation check out the my-grow project.

Deployment

make install # Install local Python dependencies (rshell & esptool)

make erase # Erase ESP32

make image # Install MicroPython on ESP32

make rsync # Install updater on ESP32

make repl # Opens a repl terminal to the ESP32

Power cycle (Ctrl-D) the ESP32, you should see the updater pull down HEAD of the configured branch on boot.

Internals

Execution of src/main.py calls updater.update() checking .version file with the SHA of the latest commit. If they are different it will create a new directory and pull down the src sub-directory. Once complete, the old src directory is deleted and the new copy is moved in its place. After that it will execute src.main with the following kargs:

import src.main
src.main.start(env=env, requests=lib.requests, logger=logger, time=t, updater=updater)

Secrets

Use src/env.py to store secrets that will be passed to main.start() so they do not need be stored in the main repository. This file is not updated via OTA and needs to be replaced manually by flashing.

Interval Updating

You may want to check for updates a regularly scheduled intervals eg. every hour. Here is an example implementation:

# Reset the device if an update is available
if state['runtime'][runtime.OTA_AUTO_UPDATE_INTERVAL] and time.time() % state['runtime'][runtime.OTA_AUTO_UPDATE_INTERVAL] == 0:
  try:
    gc.collect()
    updater.checkForUpdate()
  except Exception as e:
    log('Failed to check for OTA update:', e)

About

OTA Updater for MicroPython

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.4%
  • Makefile 3.6%