OTAUpdate.ino 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. OTAUpdate.ino, Example for the AutoConnect library.
  3. Copyright (c) 2020, Hieromon Ikasamo
  4. https://github.com/Hieromon/AutoConnect
  5. This example is an implementation of a lightweight update feature
  6. that updates the ESP8266's firmware from your web browser.
  7. You need a compiled sketch binary file to the actual update and can
  8. retrieve it using Arduino-IDE menu: [Sketck] -> [Export compiled binary].
  9. Then you will find the .bin file in your sketch folder. Select the.bin
  10. file on the update UI page to update the firmware.
  11. Notes:
  12. If you receive a following error, you need reset the module before sketch running.
  13. Update error: ERROR[11]: Invalid bootstrapping state, reset ESP8266 before updating.
  14. Refer to https://hieromon.github.io/AutoConnect/faq.html#hang-up-after-reset for details.
  15. This software is released under the MIT License.
  16. https://opensource.org/licenses/MIT
  17. */
  18. #if defined(ARDUINO_ARCH_ESP8266)
  19. #include <ESP8266WiFi.h>
  20. #include <ESP8266WebServer.h>
  21. typedef ESP8266WebServer WiFiWebServer;
  22. #elif defined(ARDUINO_ARCH_ESP32)
  23. #include <WiFi.h>
  24. #include <WebServer.h>
  25. typedef WebServer WiFiWebServer;
  26. #endif
  27. #include <AutoConnect.h>
  28. WiFiWebServer server;
  29. AutoConnect portal(server);
  30. AutoConnectConfig config;
  31. void setup() {
  32. delay(1000);
  33. Serial.begin(115200);
  34. Serial.println();
  35. // Responder of root page and apply page handled directly from WebServer class.
  36. server.on("/", []() {
  37. String content = R"(
  38. <!DOCTYPE html>
  39. <html>
  40. <head>
  41. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
  42. </head>
  43. <body>
  44. Place the root page with the sketch application.&ensp;
  45. __AC_LINK__
  46. </body>
  47. </html>
  48. )";
  49. content.replace("__AC_LINK__", String(AUTOCONNECT_LINK(COG_16)));
  50. server.send(200, "text/html", content);
  51. });
  52. config.ota = AC_OTA_BUILTIN;
  53. portal.config(config);
  54. portal.begin();
  55. }
  56. void loop() {
  57. portal.handleClient();
  58. }