<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jakub Bednarski</title>
    <description>The latest articles on DEV Community by Jakub Bednarski (@rangerdigital).</description>
    <link>https://dev.to/rangerdigital</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F287074%2F0574e4cf-3e74-4765-855b-ddc0bf6d1d82.png</url>
      <title>DEV Community: Jakub Bednarski</title>
      <link>https://dev.to/rangerdigital</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rangerdigital"/>
    <language>en</language>
    <item>
      <title>🦊 Simple OTA updates for Micropython with Senko.</title>
      <dc:creator>Jakub Bednarski</dc:creator>
      <pubDate>Tue, 16 Feb 2021 12:31:39 +0000</pubDate>
      <link>https://dev.to/rangerdigital/simple-ota-updates-for-micropython-with-senko-4lea</link>
      <guid>https://dev.to/rangerdigital/simple-ota-updates-for-micropython-with-senko-4lea</guid>
      <description>&lt;p&gt;With the rise of &lt;strong&gt;Micropython&lt;/strong&gt; usage across Espressif microcontrollers, It is worth noting the importance of &lt;strong&gt;Over-The-Air&lt;/strong&gt; updates in developing new features and maintaining security.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://i.giphy.com/media/YWH83KyJGiI9rCO3K4/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/YWH83KyJGiI9rCO3K4/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;




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


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/RangerDigital" rel="noopener noreferrer"&gt;
        RangerDigital
      &lt;/a&gt; / &lt;a href="https://github.com/RangerDigital/senko" rel="noopener noreferrer"&gt;
        senko
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      🦊 Simplest OTA update solution for your Micropython projects.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;





&lt;h2&gt;
  
  
  🛠 Operating Principle
&lt;/h2&gt;

&lt;p&gt;Senko synchronizes selected files on your microcontroller with the remote ones from the GitHub repository.&lt;/p&gt;

&lt;p&gt;Every time &lt;code&gt;.fetch()&lt;/code&gt; or &lt;code&gt;.update()&lt;/code&gt; methods are called Senko compares &lt;strong&gt;SHA1&lt;/strong&gt; hashes of local files with remote ones to determine if they are the same.&lt;/p&gt;

&lt;p&gt;If they are not, Senko saves remote files from &lt;strong&gt;GitHub&lt;/strong&gt; repository to your microcontroller. This means you need to reboot to run the latest code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🚧 You are responsible for implementing a network connection and reboot strategy!&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔥 Installation
&lt;/h2&gt;

&lt;p&gt;Senko consists of a single &lt;code&gt;senko.py&lt;/code&gt; module that you import.&lt;/p&gt;

&lt;p&gt;You can use &lt;strong&gt;uPip&lt;/strong&gt; to install Senko from &lt;strong&gt;PyPi&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;upip&lt;/span&gt;

&lt;span class="n"&gt;upip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;install&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;micropython-senko&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎉 Usage
&lt;/h2&gt;

&lt;p&gt;You should start by importing the module and creating a &lt;code&gt;Senko&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;You have to specify &lt;strong&gt;user&lt;/strong&gt; with your GitHub username, &lt;strong&gt;repo&lt;/strong&gt;, and &lt;strong&gt;files&lt;/strong&gt; that you want to keep synchronized.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# boot.py
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;senko&lt;/span&gt;

&lt;span class="n"&gt;OTA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;senko&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Senko&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ocktokit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Required
&lt;/span&gt;  &lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;octokit-iot&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Required
&lt;/span&gt;  &lt;span class="n"&gt;branch&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;master&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Optional: Defaults to "master"
&lt;/span&gt;  &lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;boot.py&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;main.py&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check out other examples in the Senko repository!&lt;/p&gt;




&lt;h3&gt;
  
  
  Updating
&lt;/h3&gt;

&lt;p&gt;Then after connecting to Wi-Fi network call &lt;code&gt;OTA.update()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# boot.py
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;senko&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;machine&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;network&lt;/span&gt;

&lt;span class="n"&gt;OTA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;senko&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Senko&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ocktokit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
   &lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;octokit-iot&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
   &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;boot.py&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;main.py&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Connect to Wi-Fi network.
&lt;/span&gt;&lt;span class="nf"&gt;connect_wlan&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;OTA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Updated to the latest version! Rebooting...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;machine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;That's It!&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This setup will try to keep &lt;code&gt;boot.py&lt;/code&gt; and &lt;code&gt;main.py&lt;/code&gt; updated every time the microcontroller boots.&lt;/p&gt;

&lt;p&gt;Check out my other projects at &lt;a href="https://bednarski.dev" rel="noopener noreferrer"&gt;https://bednarski.dev&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
