From 08562fd6236d98e0ea52c69fb9674a68ec15ad7f Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 7 Oct 2024 13:10:17 +1100 Subject: [PATCH] Config GUI improvements --- src/main.cpp | 5 ++++- src/serialParser.cpp | 1 + src/web_config.cpp | 42 ++++++++++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 32e1145..1ab8962 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,6 +62,9 @@ void setup() }); server.on(WEB_CONFIG_URL, HTTP_POST, [](AsyncWebServerRequest *request) { + request->onDisconnect([](){ + ESP.restart(); + }); request->send(200, "text/html", webConfigPOSTRequest(request)); }); @@ -150,7 +153,7 @@ void setup() if(config.getUChar("connection_type") == CONNECTION_TYPE_TUNERSTUDIO) { Serial_ECU.setRxBufferSize(2048+3); } //Maximum buffer size is 4x SD sectors (512) + 3 bytes over overhead else { Serial_ECU.setRxBufferSize(257); } //Maximum buffer sent by the ECU Serial_ECU.begin(115200); - + delay(500); while(Serial_ECU.available()) { Serial_ECU.read(); } //In case unit has restarted and ECU is still sending data over UART } diff --git a/src/serialParser.cpp b/src/serialParser.cpp index f6c1d38..77f37ae 100644 --- a/src/serialParser.cpp +++ b/src/serialParser.cpp @@ -128,6 +128,7 @@ void initSerialData() readings_JSON["correction_voltage"] = 0; readings_JSON["Battery_Voltage"] = 0; readings_JSON["AFR1"] = 0; + readings_JSON["PW1"] = 0; readings_JSON["correction_o2"] = 0; readings_JSON["correction_iat"] = 0; readings_JSON["correction_clt"] =0; diff --git a/src/web_config.cpp b/src/web_config.cpp index 9733a18..4b97deb 100644 --- a/src/web_config.cpp +++ b/src/web_config.cpp @@ -73,8 +73,8 @@ String webConfigRequest(AsyncWebServerRequest *request) response += ""; response += ""; response += "Update Dashboard Data
"; - response += ""; - response += ""; + response += "
"; + response += "
"; response += "

Manual Update

"; response += "

Upload Filesystem

"; response += "
"; @@ -84,7 +84,7 @@ String webConfigRequest(AsyncWebServerRequest *request) //response += ""; //response += "

"; response += "
"; - response += "

"; + //response += "
"; response += "

Upload Firmware

"; response += "
"; response += "File:
"; @@ -100,35 +100,53 @@ String webConfigRequest(AsyncWebServerRequest *request) String webConfigPOSTRequest(AsyncWebServerRequest *request) { bool wifiChanged = false; + String updateMessage = ""; //Respond to any parameters that were sent through if (request->hasParam("ssid", true)) { - Serial.println("Changing Wifi network. New ssid: " + request->getParam("ssid", true)->value()); + updateMessage = "Changing Wifi network. New ssid: " + request->getParam("ssid", true)->value(); config.putString("ssid", request->getParam("ssid", true)->value()); } if (request->hasParam("wpa-psk", true)) { - Serial.println("New wifi password received"); + updateMessage = "New wifi password received"; config.putString("wpa-psk", request->getParam("wpa-psk", true)->value()); } if (request->hasParam("ap-ssid", true)) { - Serial.println("Changing AP SSID. New ssid: " + request->getParam("ap-ssid", true)->value()); + updateMessage = "Changing AP SSID. New ssid: " + request->getParam("ap-ssid", true)->value(); config.putString("ap-ssid", request->getParam("ap-ssid", true)->value()); } if (request->hasParam("connection_type", true)) { - Serial.println("Changing Connection Type: " + request->getParam("connection_type", true)->value()); + updateMessage = "Changing Connection Type: " + request->getParam("connection_type", true)->value(); char c = request->getParam("connection_type", true)->value()[0]; config.putUChar("connection_type", atoi(&c) ); } + Serial.println(updateMessage); - if(wifiChanged) - { - //Delayed reboot? Need to return the POST request and then reboot or restart network - } + //Create the updates page + String updatePage = staticHTML_head(); + updatePage += staticCSS_config(); + updatePage += ""; + updatePage += ""; + updatePage += "
"; + updatePage += staticHTML_logo(); + updatePage += ""; + updatePage += ""; + updatePage += "
"; + + updatePage += "
"; + updatePage += "
"; + updatePage += "

Config Saved


"; + updatePage += "Please wait 10 seconds for system to restart"; + updatePage += "




"; + updatePage += "Message: "; + updatePage += updateMessage; + + updatePage += "
"; - return String("Config Saved"); + return updatePage; } String scanWifi(AsyncWebServerRequest *request)