From d26c41f8a001af0b36cbd28c9da8714af4c28880 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Wed, 15 Apr 2020 21:21:06 +0900 Subject: [PATCH] Adds OTAUpdate.ino as an example --- .travis.yml | 1 + examples/OTAUpdate/OTAUpdate.ino | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 examples/OTAUpdate/OTAUpdate.ino diff --git a/.travis.yml b/.travis.yml index 32f212f..0c479d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,4 +47,5 @@ script: - buildExampleSketch mqttRSSI_NA - buildExampleSketch Simple - buildExampleSketch Update + - buildExampleSketch OTAUpdate - buildExampleSketch WebUpdate diff --git a/examples/OTAUpdate/OTAUpdate.ino b/examples/OTAUpdate/OTAUpdate.ino new file mode 100644 index 0000000..a9fe8f7 --- /dev/null +++ b/examples/OTAUpdate/OTAUpdate.ino @@ -0,0 +1,66 @@ +/* + OTAUpdate.ino, Example for the AutoConnect library. + Copyright (c) 2020, Hieromon Ikasamo + https://github.com/Hieromon/AutoConnect + This example is an implementation of a lightweight update feature + that updates the ESP8266's firmware from your web browser. + You need a compiled sketch binary file to the actual update and can + retrieve it using Arduino-IDE menu: [Sketck] -> [Export compiled binary]. + Then you will find the .bin file in your sketch folder. Select the.bin + file on the update UI page to update the firmware. + + Notes: + If you receive a following error, you need reset the module before sketch running. + Update error: ERROR[11]: Invalid bootstrapping state, reset ESP8266 before updating. + Refer to https://hieromon.github.io/AutoConnect/faq.html#hang-up-after-reset for details. + + This software is released under the MIT License. + https://opensource.org/licenses/MIT +*/ + +#if defined(ARDUINO_ARCH_ESP8266) +#include +#include +typedef ESP8266WebServer WiFiWebServer; +#elif defined(ARDUINO_ARCH_ESP32) +#include +#include +typedef WebServer WiFiWebServer; +#endif +#include + +WiFiWebServer server; +AutoConnect portal(server); +AutoConnectConfig config; + +void setup() { + delay(1000); + Serial.begin(115200); + Serial.println(); + + // Responder of root page and apply page handled directly from WebServer class. + server.on("/", []() { + String content = R"( + + + + + + +Place the root page with the sketch application.  +__AC_LINK__ + + + )"; + content.replace("__AC_LINK__", String(AUTOCONNECT_LINK(COG_16))); + server.send(200, "text/html", content); + }); + + config.ota = AC_OTA_BUILTIN; + portal.config(config); + portal.begin(); +} + +void loop() { + portal.handleClient(); +}