mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 01:39:30 +02:00
Make Wifi channel configurable
This commit is contained in:
parent
224c33ec1d
commit
21eda56c9e
7 changed files with 18 additions and 12 deletions
|
@ -20,7 +20,6 @@ volatile CAN_Configuration can_config = {
|
||||||
.shunt = CAN_NATIVE // (OPTIONAL) Which CAN is your shunt connected to?
|
.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
|
// Set your Static IP address. Only used incase WIFICONFIG is set in USER_SETTINGS.h
|
||||||
IPAddress local_IP(192, 168, 10, 150);
|
IPAddress local_IP(192, 168, 10, 150);
|
||||||
IPAddress gateway(192, 168, 10, 1);
|
IPAddress gateway(192, 168, 10, 1);
|
||||||
|
@ -30,12 +29,8 @@ std::string ssid;
|
||||||
std::string password;
|
std::string password;
|
||||||
std::string passwordAP;
|
std::string passwordAP;
|
||||||
|
|
||||||
const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection
|
|
||||||
|
|
||||||
|
|
||||||
// MQTT
|
// MQTT
|
||||||
|
|
||||||
|
|
||||||
const char* mqtt_topic_name =
|
const char* mqtt_topic_name =
|
||||||
"BE"; // Custom MQTT topic name. Previously, the name was automatically set to "battery-emulator_esp32-XXXXXX"
|
"BE"; // Custom MQTT topic name. Previously, the name was automatically set to "battery-emulator_esp32-XXXXXX"
|
||||||
const char* mqtt_object_id_prefix =
|
const char* mqtt_object_id_prefix =
|
||||||
|
|
|
@ -21,7 +21,6 @@ typedef struct {
|
||||||
} CAN_Configuration;
|
} CAN_Configuration;
|
||||||
extern volatile CAN_Configuration can_config;
|
extern volatile CAN_Configuration can_config;
|
||||||
extern volatile uint8_t AccessPointEnabled;
|
extern volatile uint8_t AccessPointEnabled;
|
||||||
extern const uint8_t wifi_channel;
|
|
||||||
extern volatile float CHARGER_SET_HV;
|
extern volatile float CHARGER_SET_HV;
|
||||||
extern volatile float CHARGER_MAX_HV;
|
extern volatile float CHARGER_MAX_HV;
|
||||||
extern volatile float CHARGER_MIN_HV;
|
extern volatile float CHARGER_MIN_HV;
|
||||||
|
|
|
@ -157,6 +157,7 @@ void init_stored_settings() {
|
||||||
|
|
||||||
// WIFI AP is enabled by default unless disabled in the settings
|
// WIFI AP is enabled by default unless disabled in the settings
|
||||||
wifiap_enabled = settings.getBool("WIFIAPENABLED", true);
|
wifiap_enabled = settings.getBool("WIFIAPENABLED", true);
|
||||||
|
wifi_channel = settings.getUInt("WIFICHANNEL", 2000);
|
||||||
passwordAP = settings.getString("APPASSWORD", "123456789").c_str();
|
passwordAP = settings.getString("APPASSWORD", "123456789").c_str();
|
||||||
mqtt_enabled = settings.getBool("MQTTENABLED", false);
|
mqtt_enabled = settings.getBool("MQTTENABLED", false);
|
||||||
mqtt_timeout_ms = settings.getUInt("MQTTTIMEOUT", 2000);
|
mqtt_timeout_ms = settings.getUInt("MQTTTIMEOUT", 2000);
|
||||||
|
|
|
@ -290,6 +290,10 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
|
||||||
return settings.getBool("WIFIAPENABLED", wifiap_enabled) ? "checked" : "";
|
return settings.getBool("WIFIAPENABLED", wifiap_enabled) ? "checked" : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (var == "WIFICHANNEL") {
|
||||||
|
return String(settings.getUInt("WIFICHANNEL", 0));
|
||||||
|
}
|
||||||
|
|
||||||
if (var == "PERFPROFILE") {
|
if (var == "PERFPROFILE") {
|
||||||
return settings.getBool("PERFPROFILE") ? "checked" : "";
|
return settings.getBool("PERFPROFILE") ? "checked" : "";
|
||||||
}
|
}
|
||||||
|
@ -867,7 +871,7 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
||||||
<div style='background-color: #303E47; padding: 10px; margin-bottom: 10px;border-radius: 50px'>
|
<div style='background-color: #303E47; padding: 10px; margin-bottom: 10px;border-radius: 50px'>
|
||||||
<h4 style='color: white;'>SSID: <span id='SSID'>%SSID%</span><button onclick='editSSID()'>Edit</button></h4>
|
<h4 style='color: white;'>SSID: <span id='SSID'>%SSID%</span><button onclick='editSSID()'>Edit</button></h4>
|
||||||
<h4 style='color: white;'>Password: ######## <span id='Password'></span> <button onclick='editPassword()'>Edit</button></h4>
|
<h4 style='color: white;'>Password: ######## <span id='Password'></span> <button onclick='editPassword()'>Edit</button></h4>
|
||||||
|
|
||||||
<div style='background-color: #404E47; padding: 10px; margin-bottom: 10px;border-radius: 50px'>
|
<div style='background-color: #404E47; padding: 10px; margin-bottom: 10px;border-radius: 50px'>
|
||||||
<div style='max-width: 500px;'>
|
<div style='max-width: 500px;'>
|
||||||
<form action='saveSettings' method='post' style='display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; align-items: center;'>
|
<form action='saveSettings' method='post' style='display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; align-items: center;'>
|
||||||
|
@ -1042,16 +1046,17 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
||||||
|
|
||||||
<label>Normally Open inverter disconnect contactor: </label>
|
<label>Normally Open inverter disconnect contactor: </label>
|
||||||
<input type='checkbox' name='NOINVDISC' value='on' style='margin-left: 0;' %NOINVDISC% />
|
<input type='checkbox' name='NOINVDISC' value='on' style='margin-left: 0;' %NOINVDISC% />
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label>Use CanFD as classic CAN: </label>
|
<label>Use CanFD as classic CAN: </label>
|
||||||
<input type='checkbox' name='CANFDASCAN' value='on' style='margin-left: 0;' %CANFDASCAN% />
|
<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% />
|
<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>
|
<label>Custom hostname: </label>
|
||||||
<input type='text' name='HOSTNAME' value="%HOSTNAME%" />
|
<input type='text' name='HOSTNAME' value="%HOSTNAME%" />
|
||||||
|
|
||||||
|
|
|
@ -463,6 +463,9 @@ void init_webserver() {
|
||||||
} else if (p->name() == "MAXPRETIME") {
|
} else if (p->name() == "MAXPRETIME") {
|
||||||
auto type = atoi(p->value().c_str());
|
auto type = atoi(p->value().c_str());
|
||||||
settings.saveUInt("MAXPRETIME", type);
|
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") {
|
} else if (p->name() == "HOSTNAME") {
|
||||||
settings.saveString("HOSTNAME", p->value().c_str());
|
settings.saveString("HOSTNAME", p->value().c_str());
|
||||||
} else if (p->name() == "MQTTSERVER") {
|
} else if (p->name() == "MQTTSERVER") {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
bool wifi_enabled = true;
|
bool wifi_enabled = true;
|
||||||
bool wifiap_enabled = true;
|
bool wifiap_enabled = true;
|
||||||
bool mdns_enabled = true; //If true, allows battery monitor te be found by .local address
|
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 custom_hostname; //If not set, the default naming format 'esp32-XXXXXX' will be used
|
||||||
std::string ssidAP;
|
std::string ssidAP;
|
||||||
|
@ -150,7 +151,9 @@ void connectToWiFi() {
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
lastReconnectAttempt = millis(); // Reset the reconnect attempt timer
|
lastReconnectAttempt = millis(); // Reset the reconnect attempt timer
|
||||||
logging.println("Connecting to Wi-Fi...");
|
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(),
|
DEBUG_PRINTF("Connecting to Wi-Fi SSID: %s, password: %s, Channel: %d\n", ssid.c_str(), password.c_str(),
|
||||||
wifi_channel);
|
wifi_channel);
|
||||||
WiFi.begin(ssid.c_str(), password.c_str(), wifi_channel);
|
WiFi.begin(ssid.c_str(), password.c_str(), wifi_channel);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
extern std::string ssid;
|
extern std::string ssid;
|
||||||
extern std::string password;
|
extern std::string password;
|
||||||
extern const uint8_t wifi_channel;
|
extern uint16_t wifi_channel;
|
||||||
extern std::string ssidAP;
|
extern std::string ssidAP;
|
||||||
extern std::string passwordAP;
|
extern std::string passwordAP;
|
||||||
extern std::string custom_hostname;
|
extern std::string custom_hostname;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue