You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
AutoConnect/docs/otaserver.html

1191 lines
45 KiB

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="ESP8266/ESP32 WLAN configuration at run time with web interface">
<link rel="canonical" href="https://Hieromon.github.io/AutoConnect/otaserver.html">
<meta name="author" content="Hieromon Ikasamo">
<meta name="lang:clipboard.copy" content="Copy to clipboard">
<meta name="lang:clipboard.copied" content="Copied to clipboard">
<meta name="lang:search.language" content="en">
<meta name="lang:search.pipeline.stopwords" content="True">
<meta name="lang:search.pipeline.trimmer" content="True">
<meta name="lang:search.result.none" content="No matching documents">
<meta name="lang:search.result.one" content="1 matching document">
<meta name="lang:search.result.other" content="# matching documents">
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.1, mkdocs-material-4.6.3">
<title>Using Update Server - AutoConnect for ESP8266/ESP32</title>
<link rel="stylesheet" href="assets/stylesheets/application.adb8469c.css">
<link rel="stylesheet" href="assets/stylesheets/application-palette.a8b3c06d.css">
<meta name="theme-color" content="#3f51b5">
<script src="assets/javascripts/modernizr.86422ebf.js"></script>
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
<link rel="stylesheet" href="assets/fonts/material-icons.css">
<link rel="stylesheet" href="css/paragraph.css">
<link rel="stylesheet" href="css/extra.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
<script>
window.ga = window.ga || function() {
(ga.q = ga.q || []).push(arguments)
}
ga.l = +new Date
/* Setup integration and send page view */
ga("create", "UA-116150854-1", "auto")
ga("set", "anonymizeIp", true)
ga("send", "pageview")
/* Register handler to log search on blur */
document.addEventListener("DOMContentLoaded", () => {
if (document.forms.search) {
var query = document.forms.search.query
query.addEventListener("blur", function() {
if (this.value) {
var path = document.location.pathname;
ga("send", "pageview", path + "?q=" + this.value)
}
})
}
})
</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>
</head>
<body dir="ltr" data-md-color-primary="indigo" data-md-color-accent="indigo">
<svg class="md-svg">
<defs>
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448" viewBox="0 0 416 448" id="__github"><path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19T128 352t-18.125-8.5-10.75-19T96 304t3.125-20.5 10.75-19T128 256t18.125 8.5 10.75 19T160 304zm160 0q0 10-3.125 20.5t-10.75 19T288 352t-18.125-8.5-10.75-19T256 304t3.125-20.5 10.75-19T288 256t18.125 8.5 10.75 19T320 304zm40 0q0-30-17.25-51T296 232q-10.25 0-48.75 5.25Q229.5 240 208 240t-39.25-2.75Q130.75 232 120 232q-29.5 0-46.75 21T56 304q0 22 8 38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0 37.25-1.75t35-7.375 30.5-15 20.25-25.75T360 304zm56-44q0 51.75-15.25 82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5T212 416q-19.5 0-35.5-.75t-36.875-3.125-38.125-7.5-34.25-12.875T37 371.5t-21.5-28.75Q0 312 0 260q0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25 30.875Q171.5 96 212 96q37 0 70 8 26.25-20.5 46.75-30.25T376 64q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34 99.5z"/></svg>
</defs>
</svg>
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
<a href="#updates-with-the-update-server" tabindex="0" class="md-skip">
Skip to content
</a>
<header class="md-header" data-md-component="header">
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" aria-label="AutoConnect for ESP8266/ESP32" class="md-header-nav__button md-logo">
<img alt="logo" src="images/arduino-logo.svg" width="24" height="24">
</a>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
</div>
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
AutoConnect for ESP8266/ESP32
</span>
<span class="md-header-nav__topic">
Using Update Server
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" aria-label="search" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
<label class="md-icon md-search__icon" for="__search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
&#xE5CD;
</button>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="result">
<div class="md-search-result__meta">
Type to start searching
</div>
<ol class="md-search-result__list"></ol>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<div class="md-header-nav__source">
<a href="https://github.com/Hieromon/AutoConnect" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
Hieromon/AutoConnect
</div>
</a>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container">
<main class="md-main" role="main">
<div class="md-main__inner md-grid" data-md-component="container">
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" data-md-level="0">
<label class="md-nav__title md-nav__title--site" for="__drawer">
<a href="https://Hieromon.github.io/AutoConnect/" title="AutoConnect for ESP8266/ESP32" class="md-nav__button md-logo">
<img alt="logo" src="images/arduino-logo.svg" width="48" height="48">
</a>
AutoConnect for ESP8266/ESP32
</label>
<div class="md-nav__source">
<a href="https://github.com/Hieromon/AutoConnect" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
Hieromon/AutoConnect
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="index.html" title="Overview" class="md-nav__link">
Overview
</a>
</li>
<li class="md-nav__item">
<a href="gettingstarted.html" title="Getting started" class="md-nav__link">
Getting started
</a>
</li>
<li class="md-nav__item">
<a href="menu.html" title="AutoConnect menu" class="md-nav__link">
AutoConnect menu
</a>
</li>
<li class="md-nav__item">
<a href="basicusage.html" title="Basic usage" class="md-nav__link">
Basic usage
</a>
</li>
<li class="md-nav__item">
<a href="advancedusage.html" title="Advanced usage" class="md-nav__link">
Advanced usage
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-6" type="checkbox" id="nav-6">
<label class="md-nav__link" for="nav-6">
Custom Web pages
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-6">
Custom Web pages
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="acintro.html" title="Custom Web pages with AutoConnect" class="md-nav__link">
Custom Web pages with AutoConnect
</a>
</li>
<li class="md-nav__item">
<a href="acelements.html" title="AutoConnectElements" class="md-nav__link">
AutoConnectElements
</a>
</li>
<li class="md-nav__item">
<a href="acjson.html" title="Custom Web pages with JSON" class="md-nav__link">
Custom Web pages with JSON
</a>
</li>
<li class="md-nav__item">
<a href="achandling.html" title="Handling the custom Web pages" class="md-nav__link">
Handling the custom Web pages
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-7" type="checkbox" id="nav-7" checked>
<label class="md-nav__link" for="nav-7">
OTA Updates
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-7">
OTA Updates
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="otaupdate.html" title="OTA Updates" class="md-nav__link">
OTA Updates
</a>
</li>
<li class="md-nav__item">
<a href="otabrowser.html" title="Using Web Browser" class="md-nav__link">
Using Web Browser
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
Using Update Server
</label>
<a href="otaserver.html" title="Using Update Server" class="md-nav__link md-nav__link--active">
Using Update Server
</a>
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#updates-with-the-update-server" class="md-nav__link">
Updates with the update server
</a>
<nav class="md-nav">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#how-to-embed-autoconnectupdate-to-your-sketch" class="md-nav__link">
How to embed AutoConnectUpdate to your sketch
</a>
</li>
<li class="md-nav__item">
<a href="#behavior-of-the-autoconnectupdate-class" class="md-nav__link">
Behavior of the AutoConnectUpdate class
</a>
</li>
<li class="md-nav__item">
<a href="#update-server-for-the-autoconnectupdate-class" class="md-nav__link">
Update server for the AutoConnectUpdate class
</a>
</li>
<li class="md-nav__item">
<a href="#http-contents-and-the-sequence-for-the-autoconnectupdate-class" class="md-nav__link">
HTTP contents and the sequence for the AutoConnectUpdate class
</a>
<nav class="md-nav">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#1-http-url-query-for-the-catalog-list-of-the-updatable" class="md-nav__link">
1. HTTP URL query for the catalog list of the updatable
</a>
</li>
<li class="md-nav__item">
<a href="#2-the-catalog-list-content" class="md-nav__link">
2. The catalog list content
</a>
</li>
<li class="md-nav__item">
<a href="#3-the-binary-sketch-file-used-for-updating" class="md-nav__link">
3. The binary sketch file used for updating
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-8" type="checkbox" id="nav-8">
<label class="md-nav__link" for="nav-8">
Library APIs
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-8">
Library APIs
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="api.html" title="AutoConnect API" class="md-nav__link">
AutoConnect API
</a>
</li>
<li class="md-nav__item">
<a href="apiaux.html" title="AutoConnectAux API" class="md-nav__link">
AutoConnectAux API
</a>
</li>
<li class="md-nav__item">
<a href="apiconfig.html" title="AutoConnectConfig API" class="md-nav__link">
AutoConnectConfig API
</a>
</li>
<li class="md-nav__item">
<a href="apielements.html" title="AutoConnectElements API" class="md-nav__link">
AutoConnectElements API
</a>
</li>
<li class="md-nav__item">
<a href="apiupdate.html" title="AutoConnectUpdate API" class="md-nav__link">
AutoConnectUpdate API
</a>
</li>
<li class="md-nav__item">
<a href="apiextra.html" title="Something extra" class="md-nav__link">
Something extra
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-9" type="checkbox" id="nav-9">
<label class="md-nav__link" for="nav-9">
Examples
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-9">
Examples
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="howtoembed.html" title="How to embed" class="md-nav__link">
How to embed
</a>
</li>
<li class="md-nav__item">
<a href="datatips.html" title="Tips for data conversion" class="md-nav__link">
Tips for data conversion
</a>
</li>
<li class="md-nav__item">
<a href="menuize.html" title="Attach the menu" class="md-nav__link">
Attach the menu
</a>
</li>
<li class="md-nav__item">
<a href="wojson.html" title="Custom Web pages w/o JSON" class="md-nav__link">
Custom Web pages w/o JSON
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-10" type="checkbox" id="nav-10">
<label class="md-nav__link" for="nav-10">
Appendix
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-10">
Appendix
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="lsbegin.html" title="Inside AutoConnect::begin" class="md-nav__link">
Inside AutoConnect::begin
</a>
</li>
<li class="md-nav__item">
<a href="credit.html" title="Saved credentials access" class="md-nav__link">
Saved credentials access
</a>
</li>
<li class="md-nav__item">
<a href="acupload.html" title="File upload handler" class="md-nav__link">
File upload handler
</a>
</li>
<li class="md-nav__item">
<a href="colorized.html" title="Custom colorized" class="md-nav__link">
Custom colorized
</a>
</li>
<li class="md-nav__item">
<a href="changelabel.html" title="Change label text" class="md-nav__link">
Change label text
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="faq.html" title="FAQ" class="md-nav__link">
FAQ
</a>
</li>
<li class="md-nav__item">
<a href="changelog.html" title="Change log" class="md-nav__link">
Change log
</a>
</li>
<li class="md-nav__item">
<a href="license.html" title="License" class="md-nav__link">
License
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#updates-with-the-update-server" class="md-nav__link">
Updates with the update server
</a>
<nav class="md-nav">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#how-to-embed-autoconnectupdate-to-your-sketch" class="md-nav__link">
How to embed AutoConnectUpdate to your sketch
</a>
</li>
<li class="md-nav__item">
<a href="#behavior-of-the-autoconnectupdate-class" class="md-nav__link">
Behavior of the AutoConnectUpdate class
</a>
</li>
<li class="md-nav__item">
<a href="#update-server-for-the-autoconnectupdate-class" class="md-nav__link">
Update server for the AutoConnectUpdate class
</a>
</li>
<li class="md-nav__item">
<a href="#http-contents-and-the-sequence-for-the-autoconnectupdate-class" class="md-nav__link">
HTTP contents and the sequence for the AutoConnectUpdate class
</a>
<nav class="md-nav">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#1-http-url-query-for-the-catalog-list-of-the-updatable" class="md-nav__link">
1. HTTP URL query for the catalog list of the updatable
</a>
</li>
<li class="md-nav__item">
<a href="#2-the-catalog-list-content" class="md-nav__link">
2. The catalog list content
</a>
</li>
<li class="md-nav__item">
<a href="#3-the-binary-sketch-file-used-for-updating" class="md-nav__link">
3. The binary sketch file used for updating
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content">
<article class="md-content__inner md-typeset">
<h1>Using Update Server</h1>
<h2 id="updates-with-the-update-server">Updates with the update server<a class="headerlink" href="#updates-with-the-update-server" title="Permanent link">&para;</a></h2>
<p>Since the v1.0.0 release, AutoConnect provides new feature for updating sketch firmware of ESP8266 or ESP32 modules via OTA using the <a href="apiupdate.html#autoconnectupdate">AutoConnectUpdate</a> class that is an implementation of the Sketch binary update by the HTTP server mentioned in the <a href="https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html#http-server">OTA update</a> of the ESP8266 Arduino Core documentation, which inherits from the ESP8266HTTPUpdate class (as HTTPUpdate class in the case of ESP32). It acts as a client agent for a series of update operations.</p>
<p>This method allows you to remotely update the ESP module's firmware beyond the network segments from the update server, as long as you can ensure proper routing and forwarding.</p>
<p><img src="images/updateserver.png" width="380" /></p>
<p>If you choose this update method, you need to prepare the server process as a variant of the HTTP server that supplies the binary sketch files to the updating client agent. Its server requires to be able to handle the HTTP headers extended by ESP8266HTTPUpdate class as described in the <a href="https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html#server-request-handling">ESP8266 Arduino Core documentation</a>. There are various implementations of the update server that provide binary sketch files. For example, the ESP8266 Arduino Core documentation suggests an <a href="https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html#id5">advanced updater</a> php script that can be fully communicated with the client agent using the ESP8266HTTPUpdate class. That is, the update server for AutoConnect must work with the client agent, and its implementation should make the handshake well with the AutoConnectUpdate class which wraps an ESP8266HTTPUpdate class.<br />
The AutoConnect library provides an update server script implemented in Python that can combine with the AutoConnectUpdate class.</p>
<h3 id="how-to-embed-autoconnectupdate-to-your-sketch"><i class="fa fa-edit"></i> How to embed AutoConnectUpdate to your sketch<a class="headerlink" href="#how-to-embed-autoconnectupdate-to-your-sketch" title="Permanent link">&para;</a></h3>
<p>To embed the AutoConnectUpdate class into your sketch, basically follow these steps:</p>
<ol>
<li>Declare an ESP8266WebServer object. (In ESP32, as WebServer)</li>
<li>Declare an AutoConnect object with an ESP8266WebServer object.</li>
<li>Declare an <a href="apiupdate.html">AutoConnectUpdate</a> object with the update server address and the HTTP port as parameters.</li>
<li>Invokes <a href="api.html#begin">AutoConnect::begin</a> function.</li>
<li>Attach the AutoConnectUpdate object to AutoConnect using <a href="apiupdate.html#attach">AutoConnectUpdate::attach</a> function.</li>
<li>Invokes <a href="api.html#handleclient">AutoConnect::handleClient</a> function in the <code>loop()</code>.</li>
</ol>
<div class="codehilite" style="background: #272822"><pre style="line-height: 125%"><span></span><code><span style="color: #7a7a7a">#include</span> <span style="color: #7a7a7a">&lt;ESP8266WiFi.h&gt;</span>
<span style="color: #7a7a7a">#include</span> <span style="color: #7a7a7a">&lt;ESP8266WebServer.h&gt;</span>
<span style="color: #7a7a7a">#include</span> <span style="color: #7a7a7a">&lt;AutoConnect.h&gt;</span>
<span style="color: #f8f8f2">ESP8266WebServer</span> <span style="color: #f8f8f2">server;</span> <span style="color: #7a7a7a">// Step #1</span>
<span style="color: #f8f8f2">AutoConnect</span> <span style="color: #f8f8f2">portal;</span> <span style="color: #7a7a7a">// Step #2</span>
<span style="color: #f8f8f2">AutoConnectUpdate</span> <span style="color: #a6e22e">update</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74">&quot;192.168.0.100&quot;</span><span style="color: #f8f8f2">,</span> <span style="color: #ae81ff">8000</span><span style="color: #f8f8f2">);</span> <span style="color: #7a7a7a">// Step #3</span>
<span style="color: #66d9ef">void</span> <span style="color: #a6e22e">setup</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
<span style="color: #66d9ef">if</span> <span style="color: #f8f8f2">(portal.begin())</span> <span style="color: #f8f8f2">{</span> <span style="color: #7a7a7a">// Step #4</span>
<span style="color: #f8f8f2">update.attach(portal);</span> <span style="color: #7a7a7a">// Step #5</span>
<span style="color: #f8f8f2">}</span>
<span style="color: #f8f8f2">}</span>
<span style="color: #66d9ef">void</span> <span style="color: #a6e22e">loop</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">{</span>
<span style="color: #f8f8f2">portal.handleClient();</span> <span style="color: #7a7a7a">// Step #6</span>
<span style="color: #f8f8f2">}</span>
</code></pre></div>
<p><span style="display:block;margin-left:auto;margin-right:auto;width:282px;height:362px;border:1px solid lightgrey;"><img data-gifffer="images/serverupdate.gif" data-gifffer-height="360" data-gifffer-width="280" /></span></p>
<h3 id="behavior-of-the-autoconnectupdate-class"><i class="fas fa-desktop"></i> Behavior of the AutoConnectUpdate class<a class="headerlink" href="#behavior-of-the-autoconnectupdate-class" title="Permanent link">&para;</a></h3>
<p>A sketch incorporating the AutoConnectUpdate class has an extended menu item as <strong>UPDATE</strong> in the AutoConnect menu. <strong>UPDATE</strong> as menu item will be attached by the AutoConnectUpdate automatically.</p>
<p>When an UPDATE item started, its first action is requesting a <a href="#2-the-catalog-list-content">catalog list</a> of updatable binary sketch files to the <a href="#update-server-for-the-autoconnectupdate-class">update server</a>. Then the update server sends back the catalog list of stored binary sketch files to a client which is the ESP module. The AutoConnectUpdate class will display responded list to a custom Web page<sup id="fnref:1"><a class="footnote-ref" href="#fn:1">1</a></sup> on the browser.</p>
<p><img align="top" src="images/updatemenu.png" width="240" />
<img style="margin-left:30px;" src="images/updatelist.png" width="240" /></p>
<p>The substance of Available firmware list is a custom Web page by AutoConnectAux, and you can select the target binary sketch file with the radio button (AutoConnectRadio). A progress bar will appear to notify the updating status once the update has begun. When the update finished, the ESP module will reset automatically to launch a new firmware.</p>
<p><img src="images/updating.png" width="240" />
<img style="margin-left:30px;" src="images/updated.png" width="240" /></p>
<p>The AutoConnectUpdate class performs the above series of operations in conjunction with the update server. All you need to do is attach the AutoConnectUpdate class to AutoConnect and execute the <a href="api.html#handleclient">AutoConnect::handleClient</a> function in the <code>loop()</code>.</p>
<h3 id="update-server-for-the-autoconnectupdate-class"><i class="fas fa-server"></i> Update server for the AutoConnectUpdate class<a class="headerlink" href="#update-server-for-the-autoconnectupdate-class" title="Permanent link">&para;</a></h3>
<p>The above series of operations using AutoConnectUpdate class requires an update server that can work with it. AutoConnect provides an update server script implemented in Python. This server script conforms to a sketch that uses the AutoConnectUpdate class as an update client agent.<sup id="fnref:2"><a class="footnote-ref" href="#fn:2">2</a></sup></p>
<p>In the OTA platform, you can place the update server operated by the script in a location that is reachable from the ESP module on the network.</p>
<p><div class="codehilite" style="background: #272822"><pre style="line-height: 125%"><span></span><code><span style="color: #f8f8f2">updateserver.py</span> <span style="color: #f8f8f2">[-h]</span> <span style="color: #f8f8f2">[--port</span> <span style="color: #f8f8f2">PORT]</span> <span style="color: #f8f8f2">[--bind</span> <span style="color: #f8f8f2">IP_ADDRESS]</span> <span style="color: #f8f8f2">[--catalog</span> <span style="color: #f8f8f2">CATALOG]</span> <span style="color: #f8f8f2">[--log</span> <span style="color: #f8f8f2">LOG_LEVEL]</span>
</code></pre></div>
<dl class="apidl">
<dt></dt>
<dd><span class="apidef"><strong>--help | -h</strong></span><span class="apidesc">Show help message and exit.</span>
<dd><span class="apidef"><strong>--port | -p</strong></span><span class="apidesc">Specifies <strong>PORT</strong> number (Default: 8000)</span>
<dd><span class="apidef"><strong>--bind | -b</strong></span><span class="apidesc">Specifies the IP address to which the update server binds. Usually, it is the host address of the update server. When multiple NICs configured, specify one of the IP addresses. (Default: HOST IP or 127.0.0.0)</span>
<dd><span class="apidef"><strong>--catalog | -d</strong></span><span class="apidesc">Specifies the directory path on the update server that contains the binary sketch files. (Default: The current directory)</span>
<dd><span class="apidef"><strong>--log | -l</strong></span><span class="apidesc">Specifies the level of logging output. It accepts the <a href="https://docs.python.org/3/library/logging.html?highlight=logging#logging-levels">Logging Levels</a> specified in the Python logging module.</span>
</dl></p>
<div class="admonition example">
<p class="admonition-title">updateserver.py usage</p>
<ol>
<li>
<p>Python<br />
First, prepare a Python environment. It is also possible with a tiny single-board computer like the <a href="https://www.raspberrypi.org/">raspberry pi</a>. Popular distributions such as Ubuntu for Linux include Python. You can easily set up a Python 2 or 3 environment. If you are using a Mac, you already have the Python 2 environment. macOS is equipped with Python 2.7 by default. In the case of Windows OS, it is necessary to install the Python environment intentionally. Please refer to the <a href="https://wiki.python.org/moin/BeginnersGuide/Download">Python official page</a> to install Python in your environment.</p>
</li>
<li>
<p>Deploy the binary sketch files<br />
Use the Arduino IDE to output a binary file of sketches and deploy it<sup id="fnref:3"><a class="footnote-ref" href="#fn:3">3</a></sup> under the update server. The path which specifies for the <strong>--catalog</strong> option of updateServer.py is the path of the binary sketch files you deployed.</p>
</li>
<li>
<p>Start updateserver.py<br />
For example, to start the update server on the host with IP address 172.16.1.10 using 8080 port<sup id="fnref:4"><a class="footnote-ref" href="#fn:4">4</a></sup>, execute the following command:
<div class="codehilite" style="background: #272822"><pre style="line-height: 125%"><span></span><code><span style="color: #f8f8f2">python</span> <span style="color: #f8f8f2">updateserver.py</span> <span style="color: #f8f8f2">--port</span> <span style="color: #f8f8f2">8080</span> <span style="color: #f8f8f2">--bind</span> <span style="color: #f8f8f2">172.16.1.10</span> <span style="color: #f8f8f2">--catalog</span> <span style="color: #f8f8f2">bin</span> <span style="color: #f8f8f2">--log</span> <span style="color: #f8f8f2">debug</span>
</code></pre></div>
In this example assumes that the binary sketch files are deployed under the path <code>bin</code> from the current directory.</p>
</li>
</ol>
</div>
<div class="admonition note">
<p class="admonition-title">Limitations of the updateserver.py</p>
<p>The updateserver.py script equips only the minimum facility because it assumes a private small OTA platform without identifying individual modules and version restrictions etc. To operate a larger OTA platform, it is necessary to identify the individual ESP module and to consider version control and security.</p>
</div>
<h3 id="http-contents-and-the-sequence-for-the-autoconnectupdate-class"><i class="far fa-handshake"></i> HTTP contents and the sequence for the AutoConnectUpdate class<a class="headerlink" href="#http-contents-and-the-sequence-for-the-autoconnectupdate-class" title="Permanent link">&para;</a></h3>
<p>You can also equip an update server that works with the AutoConnectUpdate class. It can be improved more widely applicable by adding extensions such as version control and authentication to the updateserver.py script. It is necessary to understand the specifications related to HTTP data streams and sequences to enhance the update server that the AutoConnectUpdate class assumes.</p>
<p>This section describes the contents of the HTTP data stream required by the communication with AutoConnectUpdate class. To work correctly with the AutoConnectUpdate class, the update server must meet two requirements:</p>
<ul>
<li>The update server notifies the catalog list of updatable binary files which stored in the update server to the client agent. <sup id="fnref:5"><a class="footnote-ref" href="#fn:5">5</a></sup></li>
<li>Send an updating binary file and MD5 hash to a client in response to URI request (HTTP GET). <sup id="fnref:6"><a class="footnote-ref" href="#fn:6">6</a></sup></li>
</ul>
<p>Above requirements will be implemented on along the HTTP protocol. The AutoConnectUpdate class requests an update server to notify the client for a catalog list of binary sketch files using an HTTP URL query string. The specifications of the HTTP query and the contents of the catalog list to be returned are as follows:</p>
<h4 id="1-http-url-query-for-the-catalog-list-of-the-updatable">1. HTTP URL query for the catalog list of the updatable<a class="headerlink" href="#1-http-url-query-for-the-catalog-list-of-the-updatable" title="Permanent link">&para;</a></h4>
<p><div class="codehilite" style="background: #272822"><pre style="line-height: 125%"><span></span><code><span style="color: #66d9ef">[address]</span><span style="color: #f8f8f2">/_catalog</span><span style="color: #66d9ef">?</span><span style="color: #f8f8f2">op=list&amp;path=</span><span style="color: #66d9ef">[path]</span>
</code></pre></div>
<dl class="apidl">
<dt></dt>
<dd><span class="apidef"><strong>address</strong></span><span class="apidesc">URL of the update server</span>
<dd><span class="apidef"><strong>/_catalog</strong></span><span class="apidesc">Request path, it is fixed.</span>
<dd><span class="apidef"><strong>op</strong></span><span class="apidesc">Operation command for the update server. Currently, only '<strong>list</strong>' occurs.</span>
<dd><span class="apidef"><strong>path</strong></span><span class="apidesc">Path containing the updatable binary files on the update server.</span>
</dl></p>
<h4 id="2-the-catalog-list-content">2. The catalog list content<a class="headerlink" href="#2-the-catalog-list-content" title="Permanent link">&para;</a></h4>
<p>The response (that is, the catalog list) to the above query from the server is the following specification in JSON format.</p>
<p><div class="codehilite" style="background: #272822"><pre style="line-height: 125%"><span></span><code><span style="color: #f8f8f2">{</span>
<span style="color: #e6db74">&quot;name&quot;</span> <span style="color: #f92672">:</span> <span style="color: #a6e22e">FILE_NAME</span><span style="color: #f8f8f2">,</span>
<span style="color: #e6db74">&quot;type&quot;</span> <span style="color: #f92672">:</span> <span style="color: #a6e22e">FILE_TYPE</span><span style="color: #f8f8f2">,</span>
<span style="color: #e6db74">&quot;date&quot;</span> <span style="color: #f92672">:</span> <span style="color: #a6e22e">FILE_TIMESTAMP_DATED</span><span style="color: #f8f8f2">,</span>
<span style="color: #e6db74">&quot;time&quot;</span> <span style="color: #f92672">:</span> <span style="color: #a6e22e">FILE_TIMESTAMP_TIMED</span><span style="color: #f8f8f2">,</span>
<span style="color: #e6db74">&quot;size&quot;</span> <span style="color: #f92672">:</span> <span style="color: #a6e22e">FILE_SIZE</span>
<span style="color: #f8f8f2">}</span>
</code></pre></div>
<dl class="apidl">
<dt></dt>
<dd><span class="apidef"><strong>name</strong></span><span class="apidesc">Binary sketch file name for update (String)</span>
<dd><span class="apidef"><strong>type</strong></span><span class="apidesc">One of '<strong>bin</strong>', '<strong>directory</strong>' or '<strong>file</strong>'. AutoConnect Update recognizes only file types of '<strong>bin</strong>' as update targets. (String)</span>
<dd><span class="apidef"><strong>date</strong></span><span class="apidesc">File update date. AutoConnect v1.0.0 treats the file update date as an annotation and is not equip the version control feature yet. (String)</span>
<dd><span class="apidef"><strong>time</strong></span><span class="apidesc">File update time. AutoConnect v1.0.0 treats the file update date as an annotation and is not equip the version control feature yet. (String)</span>
<dd><span class="apidef"><strong>size</strong></span><span class="apidesc">File byte count (Numeric)</span>
</dl></p>
<p>The above JSON object is one entry. The actual catalog list is an array of this entry since it assumes that an update server will provide multiple update binary files in production. The update server should respond with the MIME type specified as <code>application/json</code> for the catalog list.<sup id="fnref:7"><a class="footnote-ref" href="#fn:7">7</a></sup></p>
<h4 id="3-the-binary-sketch-file-used-for-updating">3. The binary sketch file used for updating<a class="headerlink" href="#3-the-binary-sketch-file-used-for-updating" title="Permanent link">&para;</a></h4>
<p>The AutoConnectUpdate class issues a HTTP GET request with the specified host address and URI. The update server responds by sending back a binary sketch file with the following header:</p>
<div class="codehilite" style="background: #272822"><pre style="line-height: 125%"><span></span><code><span style="color: #f8f8f2">Content-Type</span><span style="color: #960050; background-color: #1e0010">:</span> <span style="color: #f8f8f2">application/octet-stream</span>
<span style="color: #f8f8f2">Content-Disposition</span><span style="color: #960050; background-color: #1e0010">:</span> <span style="color: #f8f8f2">attachment;</span> <span style="color: #f8f8f2">filename=</span><span style="color: #e6db74">&quot;BINARY_SKETCH_FILE_NAME&quot;</span>
<span style="color: #f8f8f2">Content-Length</span><span style="color: #960050; background-color: #1e0010">:</span> <span style="color: #f8f8f2">LENGTH_OF_CONTENT</span>
<span style="color: #f8f8f2">x-MD5</span><span style="color: #960050; background-color: #1e0010">:</span> <span style="color: #f8f8f2">HEXDIGEST</span>
</code></pre></div>
<p>The header <strong>x-MD5</strong> is a 128-bit hash value (digest in hexadecimal) that represents the checksum of the binary sketch file for updates required for the ESP8266HTTPUpdate class.</p>
<script>
window.onload = function() {
Gifffer();
};
</script>
<div class="footnote">
<hr />
<ol>
<li id="fn:1">
<p>You can scroll horizontally on the browser to see the timestamp and file size that the catalog list contains.&#160;<a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:2">
<p>The folders containing the script:<br />
For Python2: <em>AUTOCONNECT_LIBRARY_PATH</em>/src/updateserver/python2<br />
For Python3: <em>AUTOCONNECT_LIBRARY_PATH</em>/src/updateserver/python3&#160;<a class="footnote-backref" href="#fnref:2" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
<li id="fn:3">
<p>Deploying the binary sketch file output by Arduino IDE is usually just copying to the folder for deployment. However, its folder must be accessible from the updateserver.py script.&#160;<a class="footnote-backref" href="#fnref:3" title="Jump back to footnote 3 in the text">&#8617;</a></p>
</li>
<li id="fn:4">
<p>The port of the update server and the port used by the AutoConnectUpdate class must be the same.&#160;<a class="footnote-backref" href="#fnref:4" title="Jump back to footnote 4 in the text">&#8617;</a></p>
</li>
<li id="fn:5">
<p>The <strong>client agent</strong> is an instance of the AutoConnectUpdate class.&#160;<a class="footnote-backref" href="#fnref:5" title="Jump back to footnote 5 in the text">&#8617;</a></p>
</li>
<li id="fn:6">
<p>The client agent will send its URI request to the update server.&#160;<a class="footnote-backref" href="#fnref:6" title="Jump back to footnote 6 in the text">&#8617;</a></p>
</li>
<li id="fn:7">
<p>It should be represented as <code>Content-Type: application/json</code> in the HTTP response header.&#160;<a class="footnote-backref" href="#fnref:7" title="Jump back to footnote 7 in the text">&#8617;</a></p>
</li>
</ol>
</div>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-nav">
<nav class="md-footer-nav__inner md-grid">
<a href="otabrowser.html" title="Using Web Browser" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
</div>
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Previous
</span>
Using Web Browser
</span>
</div>
</a>
<a href="api.html" title="AutoConnect API" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Next
</span>
AutoConnect API
</span>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
</div>
</a>
</nav>
</div>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-footer-copyright">
<div class="md-footer-copyright__highlight">
Copyright &copy; 2018-2020 Hieromon Ikasamo
</div>
powered by
<a href="https://www.mkdocs.org" target="_blank" rel="noopener">MkDocs</a>
and
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="assets/fonts/font-awesome.css">
<a href="https://github.com/Hieromon" target="_blank" rel="noopener" title="github" class="md-footer-social__link fa fa-github"></a>
<a href="https://twitter.com/hieromon" target="_blank" rel="noopener" title="twitter" class="md-footer-social__link fa fa-twitter"></a>
</div>
</div>
</div>
</footer>
</div>
<script src="assets/javascripts/application.c33a9706.js"></script>
<script>app.initialize({version:"1.1",url:{base:"."}})</script>
<script src="js/gifffer.min.js"></script>
</body>
</html>