From b10d3af8df4601a2330b2b130bc4b5e8872767bd Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 15 Jan 2024 21:43:26 +0200 Subject: [PATCH] Make AP enabled a volatile variable --- Software/USER_SETTINGS.cpp | 5 +- Software/USER_SETTINGS.h | 1 + Software/src/devboard/webserver/webserver.cpp | 79 ++++++++++--------- 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/Software/USER_SETTINGS.cpp b/Software/USER_SETTINGS.cpp index 68273896..77c5a7d9 100644 --- a/Software/USER_SETTINGS.cpp +++ b/Software/USER_SETTINGS.cpp @@ -16,10 +16,11 @@ volatile uint16_t MAXDISCHARGEAMP = 300; //30.0A , BYD CAN specific setting, Max discharge speed in Amp (Some inverters needs to be artificially limited) #ifdef WEBSERVER -#define ENABLE_AP // Comment out this line to turn off the broadcasted AP +volatile uint8_t AccessPointEnabled = + true; //Set to either true or false incase you want the board to enable a direct wifi access point const char* ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 characters; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters; const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters; const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open -const char* versionNumber = "4.3.0"; // The current software version, shown on webserver +const char* versionNumber = "4.4.0"; // The current software version, shown on webserver #endif diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 1b9f963e..ee6f809b 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -44,4 +44,5 @@ extern volatile uint16_t MAXPERCENTAGE; extern volatile uint16_t MINPERCENTAGE; extern volatile uint16_t MAXCHARGEAMP; extern volatile uint16_t MAXDISCHARGEAMP; +extern volatile uint8_t AccessPointEnabled; #endif diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 547b8ab1..542b5422 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -42,15 +42,15 @@ unsigned long wifi_connect_current_time; const long wifi_connect_timeout = 5000; // Timeout for WiFi connect in milliseconds void init_webserver() { -// Configure WiFi -#ifdef ENABLE_AP - WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection - init_WiFi_AP(); - init_WiFi_STA(ssid, password); -#else - WiFi.mode(WIFI_STA); // Only Router connection - init_WiFi_STA(ssid, password); -#endif + // Configure WiFi + if (AccessPointEnabled) { + WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection + init_WiFi_AP(); + init_WiFi_STA(ssid, password); + } else { + WiFi.mode(WIFI_STA); // Only Router connection + init_WiFi_STA(ssid, password); + } // Route for root / web page server.on("/", HTTP_GET, @@ -64,7 +64,6 @@ void init_webserver() { server.on("/updateBatterySize", HTTP_GET, [](AsyncWebServerRequest* request) { if (request->hasParam("value")) { String value = request->getParam("value")->value(); - // Convert the string to an integer and update the variable BATTERY_WH_MAX = value.toInt(); request->send(200, "text/plain", "Updated successfully"); } else { @@ -76,8 +75,7 @@ void init_webserver() { server.on("/updateSocMax", HTTP_GET, [](AsyncWebServerRequest* request) { if (request->hasParam("value")) { String value = request->getParam("value")->value(); - // Convert the string to an integer and update the variable - MAXPERCENTAGE = value.toInt(); + MAXPERCENTAGE = value.toInt() * 10; request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -88,8 +86,7 @@ void init_webserver() { server.on("/updateSocMin", HTTP_GET, [](AsyncWebServerRequest* request) { if (request->hasParam("value")) { String value = request->getParam("value")->value(); - // Convert the string to an integer and update the variable - MINPERCENTAGE = value.toInt(); + MINPERCENTAGE = value.toInt() * 10; request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -100,8 +97,7 @@ void init_webserver() { server.on("/updateMaxChargeA", HTTP_GET, [](AsyncWebServerRequest* request) { if (request->hasParam("value")) { String value = request->getParam("value")->value(); - // Convert the string to an integer and update the variable - MAXCHARGEAMP = value.toInt(); + MAXCHARGEAMP = value.toInt() * 10; request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -112,8 +108,7 @@ void init_webserver() { server.on("/updateMaxDischargeA", HTTP_GET, [](AsyncWebServerRequest* request) { if (request->hasParam("value")) { String value = request->getParam("value")->value(); - // Convert the string to an integer and update the variable - MAXDISCHARGEAMP = value.toInt(); + MAXDISCHARGEAMP = value.toInt() * 10; request->send(200, "text/plain", "Updated successfully"); } else { request->send(400, "text/plain", "Bad Request"); @@ -394,7 +389,7 @@ String processor(const String& var) { content += "function goToSettingsPage() { window.location.href = '/settings'; }"; content += "function promptToReboot() { if (window.confirm('Are you sure you want to reboot the emulator? NOTE: If " - "Emulator is handling contactors, they will open during reboot!')) { " + "emulator is handling contactors, they will open during reboot!')) { " "rebootServer(); } }"; content += "function rebootServer() {"; content += " var xhr = new XMLHttpRequest();"; @@ -425,20 +420,20 @@ String settings_processor(const String& var) { content += "
"; // Show current settings with edit buttons and input fields - content += "

Battery size in Wh: " + String(BATTERY_WH_MAX) + - "

"; - content += "

SOC max percentage: " + String(MAXPERCENTAGE) + + content += "

Battery capacity: " + String(BATTERY_WH_MAX) + + " Wh

"; + content += "

SOC max percentage: " + String(MAXPERCENTAGE / 10.0, 1) + "

"; - content += "

SOC min percentage: " + String(MINPERCENTAGE) + + content += "

SOC min percentage: " + String(MINPERCENTAGE / 10.0, 1) + "

"; - content += "

Max charge speed: " + String(MAXCHARGEAMP) + + content += "

Max charge speed: " + String(MAXCHARGEAMP / 10.0, 1) + " A

"; - content += "

Max discharge speed: " + String(MAXDISCHARGEAMP) + + content += "

Max discharge speed: " + String(MAXDISCHARGEAMP / 10.0, 1) + " A

"; content += "