From dceefa2d2f48a4b1bd979d043e798be63b3476f4 Mon Sep 17 00:00:00 2001 From: pangodream Date: Mon, 6 Jun 2022 17:51:44 +0200 Subject: [PATCH] first commit --- keywords.txt | 13 +++++++++++++ library.json | 21 +++++++++++++++++++++ library.properties | 9 +++++++++ src/ESP2SOTA.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ src/ESP2SOTA.h | 33 ++++++++++++++++++++++++++++++++ src/index_html.h | 33 ++++++++++++++++++++++++++++++++ 6 files changed, 156 insertions(+) create mode 100644 keywords.txt create mode 100644 library.json create mode 100644 library.properties create mode 100644 src/ESP2SOTA.cpp create mode 100644 src/ESP2SOTA.h create mode 100644 src/index_html.h diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..3a704fd --- /dev/null +++ b/keywords.txt @@ -0,0 +1,13 @@ +####################################### +# Syntax Coloring Map For ESP2SOTA # +####################################### + +####################################### +# Datatypes (KEYWORD1) # +####################################### +ESP2SOTA KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) # +####################################### +begin KEYWORD2 diff --git a/library.json b/library.json new file mode 100644 index 0000000..bca8f2a --- /dev/null +++ b/library.json @@ -0,0 +1,21 @@ +{ + "name": "ESP2SOTA", + "keywords": "Self Sufficient, OTA, Update, ESP, ESP8266, ESP32, AP", + "description": "Async OTA (AP & Client WiFi modes) for ESP32/ESP8266 with no external dependencies (no jQuery needed)", + "repository": + { + "type": "git", + "url": "https://github.com/pangodream/ESP2SOTA.git" + }, + "authors": + [ + { + "name": "Alberto Iriberri", + "email": "alberto.iriberri@pangodream.es", + "maintainer": true + } + ], + "version": "1.0.0", + "frameworks": "arduino", + "platforms": "espressif" +} diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..d177aaa --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=AsyncElegantOTA +version=2.2.4 +author=Ayush Sharma +category=Communication +maintainer=Ayush Sharma +sentence=Perform OTAs for ESP8266 & ESP32 Asynchronously. +paragraph=A User Interface Library which provides interactive elements for your Over the Air Updates on ESP8266/ESP32. +url=https://github.com/ayushsharma82/AsyncElegantOTA +architectures=esp8266,esp32 diff --git a/src/ESP2SOTA.cpp b/src/ESP2SOTA.cpp new file mode 100644 index 0000000..2f20df5 --- /dev/null +++ b/src/ESP2SOTA.cpp @@ -0,0 +1,47 @@ +#include "ESP2SOTA.h" +#include "index_html.h" +//Class constructor +ESP2SOTAClass::ESP2SOTAClass(){ + +} + +#if defined(ESP8266) + void ESP2SOTAClass::begin(ESP8266WebServer *server){ +#elif defined(ESP32) + void ESP2SOTAClass::begin(WebServer *server){ +#endif + _server = server; + //Returns index.html page + _server->on("/", HTTP_GET, [&]() { + _server->sendHeader("Connection", "close"); + _server->send(200, "text/html", indexHtml); + }); + + /*handling uploading firmware file */ + _server->on("/update", HTTP_POST, [&]() { + _server->sendHeader("Connection", "close"); + _server->send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK"); + ESP.restart(); + }, [&]() { + HTTPUpload& upload = _server->upload(); + if (upload.status == UPLOAD_FILE_START) { + Serial.printf("Update: %s\n", upload.filename.c_str()); + if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size + Update.printError(Serial); + } + } else if (upload.status == UPLOAD_FILE_WRITE) { + /* flashing firmware to ESP*/ + if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { + Update.printError(Serial); + } + } else if (upload.status == UPLOAD_FILE_END) { + if (Update.end(true)) { //true to set the size to the current progress + Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); + } else { + Update.printError(Serial); + } + } + }); +} + +ESP2SOTAClass ESP2SOTA; diff --git a/src/ESP2SOTA.h b/src/ESP2SOTA.h new file mode 100644 index 0000000..64840de --- /dev/null +++ b/src/ESP2SOTA.h @@ -0,0 +1,33 @@ +#ifndef ESP2SOTA_h + #define ESP2SOTA_h + #include "Arduino.h" + #include "stdlib_noniso.h" + #if defined(ESP8266) + #define HARDWARE "ESP8266" + #include "ESP8266WebServer.h" + #include "ESP8266HTTPUpdateServer.h" + #elif defined(ESP32) + #define HARDWARE "ESP32" + #include "WebServer.h" + #include "Update.h" + #endif + + class ESP2SOTAClass{ + public: + ESP2SOTAClass(); + #if defined(ESP8266) + void begin(ESP8266WebServer *server); + #elif defined(ESP32) + void begin(WebServer *server); + #endif + private: + #if defined(ESP8266) + ESP8266WebServer *_server; + ESP8266HTTPUpdateServer _httpUpdater; + #endif + #if defined(ESP32) + WebServer *_server; + #endif + }; + extern ESP2SOTAClass ESP2SOTA; +#endif diff --git a/src/index_html.h b/src/index_html.h new file mode 100644 index 0000000..aea3af6 --- /dev/null +++ b/src/index_html.h @@ -0,0 +1,33 @@ + + const char* indexHtml = + "" + "
" + "
ESP Self Sufficient OTA
" + "
" + "" + "" + "
" + "
" + "
0%
" + "
" + "
" + "" + "";