Make Wifi channel configurable

This commit is contained in:
Daniel Öster 2025-09-02 20:12:42 +03:00
parent 224c33ec1d
commit 21eda56c9e
7 changed files with 18 additions and 12 deletions

View file

@ -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 =

View file

@ -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;

View file

@ -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);

View file

@ -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" : "";
}
@ -1044,14 +1048,15 @@ const char* getCANInterfaceName(CAN_Interface interface) {
<input type='checkbox' name='NOINVDISC' value='on' style='margin-left: 0;' %NOINVDISC% />
</div>
</div>
<label>Use CanFD as classic CAN: </label>
<input type='checkbox' name='CANFDASCAN' value='on' style='margin-left: 0;' %CANFDASCAN% />
<label>Enable WiFi AP: </label>
<label>Enable Wifi access point: </label>
<input type='checkbox' name='WIFIAPENABLED' value='on' style='margin-left: 0;' %WIFIAPENABLED% />
<label>Wifi channel 0-14: </label>
<input name='WIFICHANNEL' type='text' value="%WIFICHANNEL%" pattern="^[0-9]+$" />
<label>Custom hostname: </label>
<input type='text' name='HOSTNAME' value="%HOSTNAME%" />

View file

@ -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") {

View file

@ -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);

View file

@ -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;