From cda0209f98b6d51d9089c8c0cc5b46f64126765f Mon Sep 17 00:00:00 2001 From: Maik Hofmann Date: Thu, 25 Feb 2021 07:55:29 +0100 Subject: [PATCH] OTA Update --- HCPBridgeISR/platformio.ini | 1 + HCPBridgeISR/src/hciemulator.c | 1 - HCPBridgeISR/src/main.cpp | 50 ++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/HCPBridgeISR/platformio.ini b/HCPBridgeISR/platformio.ini index e4d26de..2dd88b2 100644 --- a/HCPBridgeISR/platformio.ini +++ b/HCPBridgeISR/platformio.ini @@ -15,3 +15,4 @@ framework = arduino lib_deps = ottowinter/ESPAsyncWebServer-esphome@^1.2.7 bblanchon/ArduinoJson@^6.17.2 + ayushsharma82/AsyncElegantOTA@^2.2.5 diff --git a/HCPBridgeISR/src/hciemulator.c b/HCPBridgeISR/src/hciemulator.c index 6ccfc21..68a4f75 100644 --- a/HCPBridgeISR/src/hciemulator.c +++ b/HCPBridgeISR/src/hciemulator.c @@ -63,7 +63,6 @@ bool skipFrame = false; - int recvTime = 0; int lastSendTime = 0; int lastStateTime = 0; diff --git a/HCPBridgeISR/src/main.cpp b/HCPBridgeISR/src/main.cpp index 47a90a7..05540bf 100644 --- a/HCPBridgeISR/src/main.cpp +++ b/HCPBridgeISR/src/main.cpp @@ -1,10 +1,12 @@ #include #include -#include "AsyncJson.h" -#include "ArduinoJson.h" +#include +#include +#include #include "hciemulator.h" #include "index_html.h" + /* create this file and add your wlan credentials const char* ssid = "MyWLANSID"; const char* password = "MYPASSWORD"; @@ -126,25 +128,36 @@ void setup(){ } 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) { - 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"); + request->send(response); }); + AsyncElegantOTA.begin(&server); server.begin(); //setup relay board @@ -166,4 +179,5 @@ void loop(){ onStatusChanged(getHCIState()); isLampOn = newisLampOn; } + AsyncElegantOTA.loop(); } \ No newline at end of file