From 5fb027b6299b4b56bed23ac2143ff56d8449551e Mon Sep 17 00:00:00 2001 From: Maik Hofmann Date: Wed, 3 Mar 2021 21:25:08 +0100 Subject: [PATCH] OTA Update on ESP32 --- HCPBridgeESP32/platformio.ini | 1 + HCPBridgeESP32/src/hciemulator.cpp | 6 +++--- HCPBridgeESP32/src/main.cpp | 33 +++++++++++++++--------------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/HCPBridgeESP32/platformio.ini b/HCPBridgeESP32/platformio.ini index 7d0e363..c84e5a1 100644 --- a/HCPBridgeESP32/platformio.ini +++ b/HCPBridgeESP32/platformio.ini @@ -16,3 +16,4 @@ lib_deps = ottowinter/ESPAsyncWebServer-esphome@^1.2.7 bblanchon/ArduinoJson@^6.17.2 plerup/EspSoftwareSerial@^6.11.6 + ayushsharma82/AsyncElegantOTA@^2.2.5 diff --git a/HCPBridgeESP32/src/hciemulator.cpp b/HCPBridgeESP32/src/hciemulator.cpp index eb015d9..13a06fd 100644 --- a/HCPBridgeESP32/src/hciemulator.cpp +++ b/HCPBridgeESP32/src/hciemulator.cpp @@ -216,7 +216,7 @@ void HCIEmulator::processDeviceStatusFrame(){ // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 //0011: 02 17 9C B9 00 08 9C 41 00 02 04 3E 03 00 00 EB CC //res=> 02 17 10 3E 00 03 01 00 00 00 00 00 00 00 00 00 00 00 00 74 1B - memcpy_P(m_txbuffer, ResponseTemplate_Fcn17_Cmd03_L08, sizeof(ResponseTemplate_Fcn17_Cmd03_L08)); + memcpy(m_txbuffer, ResponseTemplate_Fcn17_Cmd03_L08, sizeof(ResponseTemplate_Fcn17_Cmd03_L08)); m_txbuffer[0] = m_rxbuffer[0]; m_txbuffer[3] = counter; m_txbuffer[5] = cmd; @@ -326,7 +326,7 @@ void HCIEmulator::processDeviceStatusFrame(){ // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 //0011: 02 17 9C B9 00 02 9C 41 00 02 04 0F 04 17 00 7B 21 //res=> 02 17 04 0F 00 04 FD 0A 72 - memcpy_P(m_txbuffer, ResponseTemplate_Fcn17_Cmd04_L02, sizeof(ResponseTemplate_Fcn17_Cmd04_L02)); + memcpy(m_txbuffer, ResponseTemplate_Fcn17_Cmd04_L02, sizeof(ResponseTemplate_Fcn17_Cmd04_L02)); m_txbuffer[0] = m_rxbuffer[0]; m_txbuffer[3] = counter; m_txbuffer[5] = cmd; @@ -345,7 +345,7 @@ void HCIEmulator::processDeviceBusScanFrame(){ //res=> 02 17 0a 00 00 02 05 04 30 10 ff a8 45 0e df unsigned char counter = m_rxbuffer[11]; unsigned char cmd = m_rxbuffer[12]; - memcpy_P(m_txbuffer, ResponseTemplate_Fcn17_Cmd02_L05, sizeof(ResponseTemplate_Fcn17_Cmd02_L05)); + memcpy(m_txbuffer, ResponseTemplate_Fcn17_Cmd02_L05, sizeof(ResponseTemplate_Fcn17_Cmd02_L05)); m_txbuffer[0] = m_rxbuffer[0]; m_txbuffer[3] = counter; m_txbuffer[5] = cmd; diff --git a/HCPBridgeESP32/src/main.cpp b/HCPBridgeESP32/src/main.cpp index bdd8964..17914a7 100644 --- a/HCPBridgeESP32/src/main.cpp +++ b/HCPBridgeESP32/src/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "AsyncJson.h" #include "ArduinoJson.h" @@ -163,24 +164,23 @@ void setup(){ request->send(200, "text/plain", "OK"); }); - 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"){ - emulator.openDoor(); - }else{ - emulator.closeDoor(); - } - } - if(channel.equals("light")){ - switchLamp(state=="1"); - } - } - request->send(200, "text/plain", "OK"); + server.on("/sysinfo", HTTP_GET, [] (AsyncWebServerRequest *request) { + + AsyncResponseStream *response = request->beginResponseStream("application/json"); + DynamicJsonDocument root(1024); + root["freemem"] = ESP.getFreeHeap(); + root["hostname"] = WiFi.getHostname(); + root["ip"] = WiFi.localIP().toString(); + root["ssid"] = String(ssid); + root["wifistatus"] = WiFi.status(); + root["resetreason"] =esp_reset_reason(); + serializeJson(root,*response); + + request->send(response); }); + AsyncElegantOTA.begin(&server); + server.begin(); //setup relay board @@ -197,4 +197,5 @@ void setup(){ // mainloop void loop(){ + AsyncElegantOTA.loop(); } \ No newline at end of file