This library enables you to update your MicroPython projects over the air, at start-up, or whenever you choose.
To use this code:
-
Add the
ota.py
to your MicroPython device -
Create a file named
WIFI_CONFIG.py
on your MicroPython device, which contains two variables:SSID
andPASSWORD
:SSID = "my wifi hotspot name" PASSWORD = "wifi password"
-
Add this to your main program code:
from ota import OTAUpdater from WIFI_CONFIG import SSID, PASSWORD firmware_url = "https://raw.githubusercontent.com/<username>/<repo_name>/<branch_name>"
where
<username>
is your github username,<repo_name>
is the name of the repository to check for updates and<branch_name>
is the name of the branch to monitor. -
Add this to your main program code:
ota_updater = OTAUpdater(SSID, PASSWORD, firmware_url, "test.py") ota_updater.download_and_install_update_if_available()
-
On your GitHub repository, add aIt is not necessary to add the version file anymore as the versioning is based on the commit id, managed by GitHub.version.json
file, and add aversion
element to the JSON file, with a version number:[ "version":3 ]
The OTAUpdater
will connect to github over wifi using your provided wifi credentials, check what the most up-to-date version of the firmware is, compare this to a local file present on the device named version.json
, which contains the version number unique commit ID of the current on device firmware.
If the local file is not present it will create one with a version number of 0
. If the Github version is newer, it will download the latest file and overwrite the file on the device with the same name, then restart the MicroPython board.
If you find this useful, please let me know on our discord server: https://www.kevsrobots.com/discord