diff --git a/Software/src/communication/nvm/comm_nvm.cpp b/Software/src/communication/nvm/comm_nvm.cpp index 3ba5b478..df9cae1b 100644 --- a/Software/src/communication/nvm/comm_nvm.cpp +++ b/Software/src/communication/nvm/comm_nvm.cpp @@ -166,6 +166,20 @@ void init_stored_settings() { mqtt_transmit_all_cellvoltages = settings.getBool("MQTTCELLV", false); custom_hostname = settings.getString("HOSTNAME").c_str(); + static_IP_enabled = settings.getBool("STATICIP", false); + static_local_IP1 = settings.getUInt("LOCALIP1", 192); + static_local_IP2 = settings.getUInt("LOCALIP2", 168); + static_local_IP3 = settings.getUInt("LOCALIP3", 10); + static_local_IP4 = settings.getUInt("LOCALIP4", 150); + static_gateway1 = settings.getUInt("GATEWAY1", 192); + static_gateway2 = settings.getUInt("GATEWAY2", 168); + static_gateway3 = settings.getUInt("GATEWAY3", 10); + static_gateway4 = settings.getUInt("GATEWAY4", 1); + static_subnet1 = settings.getUInt("SUBNET1", 255); + static_subnet2 = settings.getUInt("SUBNET2", 255); + static_subnet3 = settings.getUInt("SUBNET3", 255); + static_subnet4 = settings.getUInt("SUBNET4", 0); + mqtt_server = settings.getString("MQTTSERVER").c_str(); mqtt_port = settings.getUInt("MQTTPORT", 0); mqtt_user = settings.getString("MQTTUSER").c_str(); diff --git a/Software/src/devboard/webserver/settings_html.cpp b/Software/src/devboard/webserver/settings_html.cpp index b2892d89..63411805 100644 --- a/Software/src/devboard/webserver/settings_html.cpp +++ b/Software/src/devboard/webserver/settings_html.cpp @@ -291,10 +291,62 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti return settings.getBool("WIFIAPENABLED", wifiap_enabled) ? "checked" : ""; } + if (var == "STATICIP") { + return settings.getBool("STATICIP") ? "checked" : ""; + } + if (var == "WIFICHANNEL") { return String(settings.getUInt("WIFICHANNEL", 0)); } + if (var == "LOCALIP1") { + return String(settings.getUInt("LOCALIP1", 0)); + } + + if (var == "LOCALIP2") { + return String(settings.getUInt("LOCALIP2", 0)); + } + + if (var == "LOCALIP3") { + return String(settings.getUInt("LOCALIP3", 0)); + } + + if (var == "LOCALIP4") { + return String(settings.getUInt("LOCALIP4", 0)); + } + + if (var == "GATEWAY1") { + return String(settings.getUInt("GATEWAY1", 0)); + } + + if (var == "GATEWAY2") { + return String(settings.getUInt("GATEWAY2", 0)); + } + + if (var == "GATEWAY3") { + return String(settings.getUInt("GATEWAY3", 0)); + } + + if (var == "GATEWAY4") { + return String(settings.getUInt("GATEWAY4", 0)); + } + + if (var == "SUBNET1") { + return String(settings.getUInt("SUBNET1", 0)); + } + + if (var == "SUBNET2") { + return String(settings.getUInt("SUBNET2", 0)); + } + + if (var == "SUBNET3") { + return String(settings.getUInt("SUBNET3", 0)); + } + + if (var == "SUBNET4") { + return String(settings.getUInt("SUBNET4", 0)); + } + if (var == "PERFPROFILE") { return settings.getBool("PERFPROFILE") ? "checked" : ""; } @@ -852,6 +904,11 @@ const char* getCANInterfaceName(CAN_Interface interface) { display: contents; } + form .if-staticip { display: none; } + form[data-staticip="true"] .if-staticip { + display: contents; + } + form .if-mqtt { display: none; } form[data-mqttenabled="true"] .if-mqtt { display: contents; @@ -869,40 +926,41 @@ const char* getCANInterfaceName(CAN_Interface interface) { R"rawliteral( -
+

SSID: %SSID%

Password: ########

+
-
-
+
- - + %BATTTYPE%
- - + +
- - - - - - - - + + + + + + + +
@@ -970,7 +1028,7 @@ const char* getCANInterfaceName(CAN_Interface interface) { - +
+ + + - +
@@ -1009,18 +1070,18 @@ const char* getCANInterfaceName(CAN_Interface interface) { %BATT2COMM% - +
- +
- +
@@ -1033,58 +1094,85 @@ const char* getCANInterfaceName(CAN_Interface interface) {
- + - + - +
- +
- - - - - + + - + + + + +
+
+
Local IP:
+ . + . + . + +
+ +
+
Gateway:
+ . + . + . + +
+ +
+
Subnet:
+ . + . + . + +
+
+
+ - + - + - + - + - + - + - +
@@ -1092,9 +1180,9 @@ const char* getCANInterfaceName(CAN_Interface interface) { - + - +
@@ -1106,14 +1194,14 @@ const char* getCANInterfaceName(CAN_Interface interface) {
- +
-

Settings saved. Reboot to take the settings into use.

+

Settings saved. Reboot to take the new settings into use.

diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 2b5f0b9d..4a173127 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -397,10 +397,10 @@ void init_webserver() { }; const char* boolSettingNames[] = { - "DBLBTR", "CNTCTRL", "CNTCTRLDBL", "PWMCNTCTRL", "PERBMSRESET", "SDLOGENABLED", - "REMBMSRESET", "EXTPRECHARGE", "USBENABLED", "CANLOGUSB", "WEBENABLED", "CANFDASCAN", - "CANLOGSD", "WIFIAPENABLED", "MQTTENABLED", "NOINVDISC", "HADISC", "MQTTTOPICS", - "MQTTCELLV", "INVICNT", "GTWRHD", "DIGITALHVIL", "PERFPROFILE", "INTERLOCKREQ", + "DBLBTR", "CNTCTRL", "CNTCTRLDBL", "PWMCNTCTRL", "PERBMSRESET", "SDLOGENABLED", "STATICIP", + "REMBMSRESET", "EXTPRECHARGE", "USBENABLED", "CANLOGUSB", "WEBENABLED", "CANFDASCAN", "CANLOGSD", + "WIFIAPENABLED", "MQTTENABLED", "NOINVDISC", "HADISC", "MQTTTOPICS", "MQTTCELLV", "INVICNT", + "GTWRHD", "DIGITALHVIL", "PERFPROFILE", "INTERLOCKREQ", }; // Handles the form POST from UI to save settings of the common image @@ -467,6 +467,42 @@ void init_webserver() { } else if (p->name() == "WIFICHANNEL") { auto type = atoi(p->value().c_str()); settings.saveUInt("WIFICHANNEL", type); + } else if (p->name() == "LOCALIP1") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("LOCALIP1", type); + } else if (p->name() == "LOCALIP2") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("LOCALIP2", type); + } else if (p->name() == "LOCALIP3") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("LOCALIP3", type); + } else if (p->name() == "LOCALIP4") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("LOCALIP4", type); + } else if (p->name() == "GATEWAY1") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("GATEWAY1", type); + } else if (p->name() == "GATEWAY2") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("GATEWAY2", type); + } else if (p->name() == "GATEWAY3") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("GATEWAY3", type); + } else if (p->name() == "GATEWAY4") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("GATEWAY4", type); + } else if (p->name() == "SUBNET1") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("SUBNET1", type); + } else if (p->name() == "SUBNET2") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("SUBNET2", type); + } else if (p->name() == "SUBNET3") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("SUBNET3", type); + } else if (p->name() == "SUBNET4") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("SUBNET4", type); } else if (p->name() == "HOSTNAME") { settings.saveString("HOSTNAME", p->value().c_str()); } else if (p->name() == "MQTTSERVER") { diff --git a/Software/src/devboard/wifi/wifi.cpp b/Software/src/devboard/wifi/wifi.cpp index b9ba7750..ab9831ee 100644 --- a/Software/src/devboard/wifi/wifi.cpp +++ b/Software/src/devboard/wifi/wifi.cpp @@ -15,10 +15,19 @@ std::string ssidAP; std::string passwordAP; // Set your Static IP address. Only used incase Static address option is set -//TODO: Make configurable via webserver -IPAddress local_IP(192, 168, 10, 150); -IPAddress gateway(192, 168, 10, 1); -IPAddress subnet(255, 255, 255, 0); +bool static_IP_enabled = false; +uint16_t static_local_IP1 = 0; +uint16_t static_local_IP2 = 0; +uint16_t static_local_IP3 = 0; +uint16_t static_local_IP4 = 0; +uint16_t static_gateway1 = 0; +uint16_t static_gateway2 = 0; +uint16_t static_gateway3 = 0; +uint16_t static_gateway4 = 0; +uint16_t static_subnet1 = 0; +uint16_t static_subnet2 = 0; +uint16_t static_subnet3 = 0; +uint16_t static_subnet4 = 0; // Configuration Parameters static const uint16_t WIFI_CHECK_INTERVAL = 2000; // 1 seconds normal check interval when last connected @@ -62,11 +71,16 @@ void init_WiFi() { // Set WiFi to auto reconnect WiFi.setAutoReconnect(true); -#ifdef WIFICONFIG - // Set static IP - WiFi.config(local_IP, gateway, subnet); -#endif - + if (static_IP_enabled) { + // Set static IP + IPAddress local_IP((uint8_t)static_local_IP1, (uint8_t)static_local_IP2, (uint8_t)static_local_IP3, + (uint8_t)static_local_IP4); + IPAddress gateway((uint8_t)static_gateway1, (uint8_t)static_gateway2, (uint8_t)static_gateway3, + (uint8_t)static_gateway4); + IPAddress subnet((uint8_t)static_subnet1, (uint8_t)static_subnet2, (uint8_t)static_subnet3, + (uint8_t)static_subnet4); + WiFi.config(local_IP, gateway, subnet); + } DEBUG_PRINTF("init_Wifi set event handlers\n"); // Initialize Wi-Fi event handlers diff --git a/Software/src/devboard/wifi/wifi.h b/Software/src/devboard/wifi/wifi.h index 0a24d283..ed6a9a89 100644 --- a/Software/src/devboard/wifi/wifi.h +++ b/Software/src/devboard/wifi/wifi.h @@ -37,5 +37,18 @@ void init_mDNS(); extern bool wifi_enabled; extern bool wifiap_enabled; extern bool mdns_enabled; +extern bool static_IP_enabled; +extern uint16_t static_local_IP1; +extern uint16_t static_local_IP2; +extern uint16_t static_local_IP3; +extern uint16_t static_local_IP4; +extern uint16_t static_gateway1; +extern uint16_t static_gateway2; +extern uint16_t static_gateway3; +extern uint16_t static_gateway4; +extern uint16_t static_subnet1; +extern uint16_t static_subnet2; +extern uint16_t static_subnet3; +extern uint16_t static_subnet4; #endif