DEV Community

Cover image for 🦊 Simple OTA updates for Micropython with Senko.
Jakub Bednarski
Jakub Bednarski

Posted on • Originally published at bednarski.dev

🦊 Simple OTA updates for Micropython with Senko.

With the rise of Micropython usage across Espressif microcontrollers, It is worth noting the importance of Over-The-Air updates in developing new features and maintaining security.



That is why I built Senko, a simple way to update your Micropython microcontroller from the GitHub repository, which I used for my ESP8266 based sensor fleet.

GitHub logo RangerDigital / senko

🦊 Simplest OTA update solution for your Micropython projects.


🛠 Operating Principle

Senko synchronizes selected files on your microcontroller with the remote ones from the GitHub repository.

Every time .fetch() or .update() methods are called Senko compares SHA1 hashes of local files with remote ones to determine if they are the same.

If they are not, Senko saves remote files from GitHub repository to your microcontroller. This means you need to reboot to run the latest code.

🚧 You are responsible for implementing a network connection and reboot strategy!


🔥 Installation

Senko consists of a single senko.py module that you import.

You can use uPip to install Senko from PyPi:

import upip

upip.install("micropython-senko")
Enter fullscreen mode Exit fullscreen mode

🎉 Usage

You should start by importing the module and creating a Senko object.

You have to specify user with your GitHub username, repo, and files that you want to keep synchronized.

# boot.py
import senko

OTA = senko.Senko(
  user="ocktokit", # Required
  repo="octokit-iot", # Required
  branch="master", # Optional: Defaults to "master"
  files = ["boot.py", "main.py"]
)
Enter fullscreen mode Exit fullscreen mode

Check out other examples in the Senko repository!


Updating

Then after connecting to Wi-Fi network call OTA.update():

# boot.py
import senko
import machine
import network

OTA = senko.Senko(
   user="ocktokit", 
   repo="octokit-iot", 
   files=["boot.py", "main.py"]
)

# Connect to Wi-Fi network.
connect_wlan()

if OTA.update():
    print("Updated to the latest version! Rebooting...")
    machine.reset()
Enter fullscreen mode Exit fullscreen mode

That's It!

This setup will try to keep boot.py and main.py updated every time the microcontroller boots.

Check out my other projects at https://bednarski.dev!

Top comments (0)