diff --git a/Software/USER_SETTINGS.cpp b/Software/USER_SETTINGS.cpp index d79a90ae..ccfa3e83 100644 --- a/Software/USER_SETTINGS.cpp +++ b/Software/USER_SETTINGS.cpp @@ -20,7 +20,6 @@ volatile CAN_Configuration can_config = { .shunt = CAN_NATIVE // (OPTIONAL) Which CAN is your shunt connected to? }; - // Set your Static IP address. Only used incase WIFICONFIG is set in USER_SETTINGS.h IPAddress local_IP(192, 168, 10, 150); IPAddress gateway(192, 168, 10, 1); @@ -30,12 +29,8 @@ std::string ssid; std::string password; std::string passwordAP; -const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection - - // MQTT - const char* mqtt_topic_name = "BE"; // Custom MQTT topic name. Previously, the name was automatically set to "battery-emulator_esp32-XXXXXX" const char* mqtt_object_id_prefix = diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index e2873c17..9f89c7bb 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -21,7 +21,6 @@ typedef struct { } CAN_Configuration; extern volatile CAN_Configuration can_config; extern volatile uint8_t AccessPointEnabled; -extern const uint8_t wifi_channel; extern volatile float CHARGER_SET_HV; extern volatile float CHARGER_MAX_HV; extern volatile float CHARGER_MIN_HV; diff --git a/Software/src/communication/nvm/comm_nvm.cpp b/Software/src/communication/nvm/comm_nvm.cpp index 2cb7a89e..2351728b 100644 --- a/Software/src/communication/nvm/comm_nvm.cpp +++ b/Software/src/communication/nvm/comm_nvm.cpp @@ -157,6 +157,7 @@ void init_stored_settings() { // WIFI AP is enabled by default unless disabled in the settings wifiap_enabled = settings.getBool("WIFIAPENABLED", true); + wifi_channel = settings.getUInt("WIFICHANNEL", 2000); passwordAP = settings.getString("APPASSWORD", "123456789").c_str(); mqtt_enabled = settings.getBool("MQTTENABLED", false); mqtt_timeout_ms = settings.getUInt("MQTTTIMEOUT", 2000); diff --git a/Software/src/devboard/webserver/settings_html.cpp b/Software/src/devboard/webserver/settings_html.cpp index 74825e3d..521805c5 100644 --- a/Software/src/devboard/webserver/settings_html.cpp +++ b/Software/src/devboard/webserver/settings_html.cpp @@ -290,6 +290,10 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti return settings.getBool("WIFIAPENABLED", wifiap_enabled) ? "checked" : ""; } + if (var == "WIFICHANNEL") { + return String(settings.getUInt("WIFICHANNEL", 0)); + } + if (var == "PERFPROFILE") { return settings.getBool("PERFPROFILE") ? "checked" : ""; } @@ -867,7 +871,7 @@ const char* getCANInterfaceName(CAN_Interface interface) {

SSID: %SSID%

Password: ########

- +
@@ -1042,16 +1046,17 @@ const char* getCANInterfaceName(CAN_Interface interface) { -
-
- + + + + diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index f1abe00c..8e3c3df4 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -463,6 +463,9 @@ void init_webserver() { } else if (p->name() == "MAXPRETIME") { auto type = atoi(p->value().c_str()); settings.saveUInt("MAXPRETIME", type); + } else if (p->name() == "WIFICHANNEL") { + auto type = atoi(p->value().c_str()); + settings.saveUInt("WIFICHANNEL", 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 869d863f..50ac3d2e 100644 --- a/Software/src/devboard/wifi/wifi.cpp +++ b/Software/src/devboard/wifi/wifi.cpp @@ -7,6 +7,7 @@ bool wifi_enabled = true; bool wifiap_enabled = true; bool mdns_enabled = true; //If true, allows battery monitor te be found by .local address +uint16_t wifi_channel = 0; std::string custom_hostname; //If not set, the default naming format 'esp32-XXXXXX' will be used std::string ssidAP; @@ -150,7 +151,9 @@ void connectToWiFi() { if (WiFi.status() != WL_CONNECTED) { lastReconnectAttempt = millis(); // Reset the reconnect attempt timer logging.println("Connecting to Wi-Fi..."); - + if (wifi_channel > 14) { + wifi_channel = 0; + } //prevent users going out of bounds DEBUG_PRINTF("Connecting to Wi-Fi SSID: %s, password: %s, Channel: %d\n", ssid.c_str(), password.c_str(), wifi_channel); WiFi.begin(ssid.c_str(), password.c_str(), wifi_channel); diff --git a/Software/src/devboard/wifi/wifi.h b/Software/src/devboard/wifi/wifi.h index 6e0b7b50..bf0ecb01 100644 --- a/Software/src/devboard/wifi/wifi.h +++ b/Software/src/devboard/wifi/wifi.h @@ -6,7 +6,7 @@ extern std::string ssid; extern std::string password; -extern const uint8_t wifi_channel; +extern uint16_t wifi_channel; extern std::string ssidAP; extern std::string passwordAP; extern std::string custom_hostname;