Giter VIP home page Giter VIP logo

senko's Introduction


Senko โ€“ OTA Updater


License: GPL v3

Senko is the simplest Over The Air updater solution for your Micropython projects based on ESP8266 and ESP32.

Senko synchronizes selected files on your microcontroller with the remote ones from GitHub repository.
I used Senko to automatically deploy the latest master branch to my ESP8266 sensors fleet.

๐Ÿšง By all means, Senko is not the best implementation, but for my simple IoT projects, It was adequate!


๐Ÿ›  Operating Principle

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 Ampy or WebREPL to load /senko/senko.py module to your microcontroller:

sudo ampy -p /dev/ttyUSB0 put senko.py

Or use uPip to install Senko from PyPi:

import upip
upip.install("micropython-senko")

๐ŸŽ‰ 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"
  working_dir="app", # Optional: Defaults to "app"
  files = ["boot.py", "main.py"]
)

Or You can also specify URL to the GitHub directory containing your code and files that you want to keep synchronized.

# boot.py
import senko

GITHUB_URL = "https://github.com/RangerDigital/senko/blob/master/examples/"
OTA = senko.Senko(url=GITHUB_URL, files=["boot.py", "main.py"])

To get the URL simply click the RAW button on the one of the files that you want to track and then strip the name of that file from it.

๐Ÿ’ก You can even specify what branch Senko will update from!


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()

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


Fetching

If you only want to check if the newer version of files exists call OTA.fetch():

if OTA.fetch():
    print("A newer version is available!")
else:
    print("Up to date!")

๐Ÿ’ก Check out a simple example of usage from examples directory!


๐Ÿšง Contributing

You are more than welcome to help me improve Senko!

Just fork this project from the master branch and submit a Pull Request (PR).


๐Ÿ“ƒ License

This project is licensed under GPL-3.0 .

senko's People

Contributors

jorgeruiz97 avatar rangerdigital avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

senko's Issues

README.md direct URL example

Attempting to use the "direct URL" example and ran into several issues:

  • It uses a non-raw URL example which presumable is unusable, but also results in very large payload, triggering a memory error
  • Tip of master requires user and repo as arguments, but they are missing
  • Extra / separator at the end

Seems /blob urls may have worked in the past, but no longer work for raw files.

Non-working:

GITHUB_URL = "https://github.com/RangerDigital/senko/blob/master/examples/"
OTA = senko.Senko(url=GITHUB_URL, files=["boot.py", "main.py"])

Working:

GITHUB_URL = "https://raw.githubusercontent.com/RangerDigital/senko/master/examples"
OTA = senko.Senko(None, None, url=GITHUB_URL, files=["boot.py", "main.py"])

Publish to PyPi

Hello is there any plan to publish this to PyPi?
In my ideal iot development I would love to Install Senko with upip:

# main.py

import upip
upip.install('micropython-senko')

I would love to contribute to this!
Congrats this is a great project! and it actually works!

Credentials

Hi, Thanks for sharing.
My git repo is private, will the git login work? if so, what part of the lib should I modify?
TIA

https://gitlab.com/

Hi,

Thanks for this easy to use lib for OTA updates.

I was testing this lib to check if I can use this to pull repo from https://gitlab.com/ and I get this error when I try.

NotImplementedError: Redirects not yet supported


OTA = senko.Senko(user="myusername", repo="myreponame", url="https://gitlab.com", working_dir="app2", files=["main.py"])
OTA.update()

( this error is coming from the urequests.py lib)
Any idea on how to fix this?

i tried this ( RAW) URL and it works fine.

OTA = senko.Senko(user="netdevopstraining", repo="micropython_ota_test", url="https://gitlab.com/netdevopstraining/micropython_ota_test/-/raw/main/app2", files=["main.py"])


Also wanted to check if this lib will work with private repos.

Thanks

Prathap

MemoryError: memory allocation failed

I noted this was originally written for targets including ESP32, but I am having trouble with memory allocation errors on micropython 1.19.1 (possibly older versions as well). It chokes on py files less than 26KB.

>>> OTA.fetch()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/senko.py", line 74, in fetch
  File "/lib/senko.py", line 53, in _check_all
  File "/lib/senko.py", line 45, in _get_file
  File "urequests.py", line 28, in text
  File "urequests.py", line 20, in content
MemoryError: memory allocation failed, allocating 12288 bytes

I have had some success in the past using gc.collect() to help remedy memory allocation failures and even modified the _get_file() method to collect before the urequests.get(). SSL connections (using mbedTLS) has severe limitations with micropython due to limited IDF heap available and even is unusable in later versions of the ESP IDF due to memory allocation behavior (micropython/micropython#8940).

From what I can tell, this is not IDF heap related and I am running out of python memory. I moved the senko check in boot.py (before main application imports and init) and it is functioning as expected without error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.