Skip to content

Commit fe314c0

Browse files
committed
Add AsyncElegantOTA
1 parent 605fc53 commit fe314c0

File tree

4 files changed

+18
-72
lines changed

4 files changed

+18
-72
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ hdgo nutzt die gleiche BUS-Schnittstelle wie die UAP1, läuft aber auf einem ESP
1010
- Bedienung per Taster (abhängig von Uhrzeit)
1111
- Automatisches Schließen (abhängig von Uhrzeit) mit Vorwarnung
1212
- Anbindung von entweder 4x4-Tastenfeld oder RFID-Leser
13-
- Paketdienst-Funktion (Fahrt auf Lüftungsposition per Code, 15s später automatisches Schließen) --> nur zulässig mit Lichtschranke!
13+
- Paketdienst-Funktion (Fahrt auf Lüftungsposition per Code, 15s später automatisches Schließen) --> nur zulässig mit Lichtschranke! (noch in Erprobung)
1414
- Aufzeichnung der letzten Fahrten (mit Code von Tastenfeld bzw. RFID)
1515
- Trace der Buskommunikation (nur für Debugging)
1616
- Anzeige der Öffnungsposition, z.B. "30% offen" (geplant)
17+
18+
Details zu den Funktionen werde ich nach und nach auch im [Wiki](https://github.com/steff393/hgdo/wiki) beschreiben.
1719

1820
## Beispiele
1921
<img src="https://i.ibb.co/7WxjjMV/Web-Interface.png">
@@ -76,11 +78,11 @@ Folgende Libraries wurden genutzt:
7678
- [NTPClient](https://github.com/arduino-libraries/NTPClient)
7779
- [MFRC522](https://github.com/miguelbalboa/MFRC522)
7880
- [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets)
79-
- [OTA via http](https://gist.github.com/JMishou/60cb762047b735685e8a09cd2eb42a60)
8081
- [WiFiManager](https://github.com/tzapu/WiFiManager)
8182
- [Web Interface](https://RandomNerdTutorials.com)
8283
- [A Beginner's Guide to the ESP8266 - article](https://github.com/tttapa/ESP8266)
8384
- [Keypad library for Arduino](https://github.com/chris--a/Keypad)
85+
- [AsyncElegantOTA](https://github.com/ayushsharma82/AsyncElegantOTA)
8486

8587
Vielen Dank!
8688

@@ -99,4 +101,7 @@ Sobald die UAP1 bzw. hgdo einmalig auf die Anfrage des Torantriebes geantwortet
99101
- Tortyp mit Taste "Hoch" einstellen, z.B. "1" für Sektionaltor
100102
- "PRG" drücken --> Anzeige "L"
101103
- "Hoch" drücken --> Lernfahrten starten (7x auf/zu) --> danach Anzeige "11" (blinkend)
102-
- 25s Warten (oder "Hoch" bis "00", dann "PRG")
104+
- 25s Warten (oder "Hoch" bis "00", dann "PRG")
105+
106+
## Unterstützung des Projektes
107+
hgdo gefällt dir? [Star this project on GitHub](https://github.com/steff393/wbec/stargazers)!

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ lib_deps =
2121
links2004/WebSockets @ ^2.3.6
2222
thomasfredericks/Bounce2 @ ^2.70
2323
chris--a/Keypad @ ^3.1.1
24+
ayushsharma82/AsyncElegantOTA @ ^2.2.6
2425
monitor_speed = 115200
2526
upload_speed = 921600

src/globalConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
const uint8_t m = 1;
1010

11-
char cfgHgdoVersion[] = "v0.0.6"; // hgdo version
11+
char cfgHgdoVersion[] = "v0.1.0"; // hgdo version
1212
char cfgBuildDate[] = "2021-10-30"; // hgdo build date
1313

1414
char cfgApSsid[32]; // SSID of the initial Access Point

src/webServer.cpp

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2021 steff393, MIT license
22

33
#include <Arduino.h>
4+
#include <AsyncElegantOTA.h>
45
#include <AsyncJson.h>
56
#include <ArduinoJson.h>
67
#include <ESP8266WiFi.h>
@@ -19,8 +20,6 @@
1920
static const uint8_t m = 2;
2021

2122

22-
static const char* otaPage PROGMEM = "%OTARESULT%<br><form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>";
23-
2423
static AsyncWebServer server(80);
2524
static boolean resetRequested = false;
2625
static boolean resetwifiRequested = false;
@@ -42,21 +41,6 @@ static void onUpload(AsyncWebServerRequest *request, String filename, size_t ind
4241
}
4342

4443

45-
static String otaProcessor(const String& var){
46-
if(Update.hasError()){
47-
return(F("Failed"));
48-
} else {
49-
return(F("OK"));
50-
}
51-
}
52-
53-
54-
static String otaProcessorEmpty(const String& var){
55-
// just replace the template string with nothing, neither ok, nor fail
56-
return String();
57-
}
58-
59-
6044
static uint8_t getSignalQuality(int rssi)
6145
{
6246
int quality = 0;
@@ -103,6 +87,11 @@ void webServer_setup() {
10387
resetwifiRequested = true;
10488
});
10589

90+
server.on("/stopcom", HTTP_GET, [](AsyncWebServerRequest *request){
91+
uap_StopCommunication();
92+
request->send(200, F("text/html"), F("Communication stopped... <a href=\"/update\">Update</a>"));
93+
});
94+
10695
server.on("/json", HTTP_GET, [](AsyncWebServerRequest *request) {
10796
DynamicJsonDocument data(2048);
10897
// modify values
@@ -134,57 +123,6 @@ void webServer_setup() {
134123
request->send(200, F("application/json"), response);
135124
});
136125

137-
// OTA via http, based on https://gist.github.com/JMishou/60cb762047b735685e8a09cd2eb42a60
138-
server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){
139-
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", otaPage, otaProcessorEmpty);
140-
response->addHeader(F("Connection"), F("close"));
141-
response->addHeader(F("Access-Control-Allow-Origin"), F("*"));
142-
request->send(response);
143-
if (request->hasParam(F("stop"))) {
144-
uap_StopCommunication();
145-
}
146-
});
147-
148-
server.on("/update", HTTP_POST, [](AsyncWebServerRequest *request){
149-
// the request handler is triggered after the upload has finished...
150-
// create the response, add header, and send response
151-
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", otaPage, otaProcessor);
152-
response->addHeader(F("Connection"), F("close"));
153-
response->addHeader(F("Access-Control-Allow-Origin"), F("*"));
154-
resetRequested = true; // Tell the main loop to restart the ESP
155-
request->send(response);
156-
},[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
157-
//Upload handler chunks in data
158-
159-
if(!index){ // if index == 0 then this is the first frame of data
160-
Serial.printf("UploadStart: %s\n", filename.c_str());
161-
Serial.setDebugOutput(true);
162-
163-
// calculate sketch space required for the update
164-
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
165-
if(!Update.begin(maxSketchSpace)){//start with max available size
166-
Update.printError(Serial);
167-
}
168-
Update.runAsync(true); // tell the updaterClass to run in async mode
169-
}
170-
171-
//Write chunked data to the free sketch space
172-
if(Update.write(data, len) != len){
173-
Update.printError(Serial);
174-
}
175-
176-
if(final){ // if the final flag is set then this is the last frame of data
177-
if(Update.end(true)){ //true to set the size to the current progress
178-
Serial.printf("Update Success: %u B\nRebooting...\n", index+len);
179-
} else {
180-
Update.printError(Serial);
181-
}
182-
Serial.setDebugOutput(false);
183-
}
184-
});
185-
// OTA via http (end)
186-
187-
188126
// add the SPIFFSEditor, which can be opened via "/edit"
189127
server.addHandler(new SPIFFSEditor("" ,"" ,LittleFS));//http_username,http_password));
190128

@@ -197,6 +135,8 @@ void webServer_setup() {
197135
server.onFileUpload(onUpload);
198136
server.onRequestBody(onBody);
199137

138+
AsyncElegantOTA.begin(&server); // Start ElegantOTA
139+
200140
server.begin();
201141
}
202142

0 commit comments

Comments
 (0)