OTA Update

This commit is contained in:
Maik Hofmann 2021-02-25 07:55:29 +01:00
parent 7c8e59d0c0
commit cda0209f98
3 changed files with 33 additions and 19 deletions

View File

@ -15,3 +15,4 @@ framework = arduino
lib_deps = lib_deps =
ottowinter/ESPAsyncWebServer-esphome@^1.2.7 ottowinter/ESPAsyncWebServer-esphome@^1.2.7
bblanchon/ArduinoJson@^6.17.2 bblanchon/ArduinoJson@^6.17.2
ayushsharma82/AsyncElegantOTA@^2.2.5

View File

@ -63,7 +63,6 @@
bool skipFrame = false; bool skipFrame = false;
int recvTime = 0; int recvTime = 0;
int lastSendTime = 0; int lastSendTime = 0;
int lastStateTime = 0; int lastStateTime = 0;

View File

@ -1,10 +1,12 @@
#include <Arduino.h> #include <Arduino.h>
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
#include "AsyncJson.h" #include <AsyncElegantOTA.h>
#include "ArduinoJson.h" #include <AsyncJson.h>
#include <ArduinoJson.h>
#include "hciemulator.h" #include "hciemulator.h"
#include "index_html.h" #include "index_html.h"
/* create this file and add your wlan credentials /* create this file and add your wlan credentials
const char* ssid = "MyWLANSID"; const char* ssid = "MyWLANSID";
const char* password = "MYPASSWORD"; const char* password = "MYPASSWORD";
@ -126,25 +128,36 @@ void setup(){
} }
request->send(200, "text/plain", "OK"); request->send(200, "text/plain", "OK");
}); });
server.on("/sysinfo", HTTP_GET, [] (AsyncWebServerRequest *request) {
String freemem;
String ResetReason;
freemem = ESP.getFreeHeap();
rst_info* rinfo = ESP.getResetInfoPtr();
//JSONencoder["uptimed"] = Day2;
//JSONencoder["uptimeh"] = Hour2;
//JSONencoder["uptimem"] = Minute2;
//JSONencoder["uptimes"] = Second2;
AsyncResponseStream *response = request->beginResponseStream("application/json");
DynamicJsonDocument root(1024);
root["freemem"] = freemem;
ResetReason += String(rinfo->reason);
ResetReason += String(" - ");
ResetReason += String(ESP.getResetReason().c_str());
root["hostname"] = String(WiFi.hostname());
root["dsdd"] = WiFi.localIP().toString();
root["ssid"] = String(ssid);
root["wifistatus"] = String(WiFi.status());
root["resetreason"] =ResetReason;
root["errors"] = rinfo->exccause;
serializeJson(root,*response);
server.on("/update", HTTP_GET, [] (AsyncWebServerRequest *request) { request->send(response);
if (request->hasParam("channel") && request->hasParam("state")) {
String channel = request->getParam("channel")->value();
String state = request->getParam("state")->value();
if(channel.equals("door")){
if(state=="1"){
openDoor();
}else{
closeDoor();
}
}
if(channel.equals("light")){
switchLamp(state=="1");
}
}
request->send(200, "text/plain", "OK");
}); });
AsyncElegantOTA.begin(&server);
server.begin(); server.begin();
//setup relay board //setup relay board
@ -166,4 +179,5 @@ void loop(){
onStatusChanged(getHCIState()); onStatusChanged(getHCIState());
isLampOn = newisLampOn; isLampOn = newisLampOn;
} }
AsyncElegantOTA.loop();
} }