(atoi(p->value().c_str()));
settings.saveUInt("SHUNTCOMM", (int)type);
+ } else if (p->name() == "HOSTNAME") {
+ settings.saveString("HOSTNAME", p->value().c_str());
} else if (p->name() == "MQTTSERVER") {
settings.saveString("MQTTSERVER", p->value().c_str());
} else if (p->name() == "MQTTPORT") {
@@ -799,7 +801,7 @@ String processor(const String& var) {
content += "";
// Compact header
- content += "" + String(ssidAP.c_str()) + "
";
+ content += "Battery Emulator
";
// Start content block
content += "";
diff --git a/Software/src/devboard/wifi/wifi.cpp b/Software/src/devboard/wifi/wifi.cpp
index 9899e8c2..545a6ed3 100644
--- a/Software/src/devboard/wifi/wifi.cpp
+++ b/Software/src/devboard/wifi/wifi.cpp
@@ -30,6 +30,12 @@ const bool mdns_enabled_default = false;
#endif
bool mdns_enabled = mdns_enabled_default;
+#ifdef CUSTOM_HOSTNAME
+std::string custom_hostname = CUSTOM_HOSTNAME;
+#else
+std::string custom_hostname;
+#endif
+
std::string ssidAP;
// Configuration Parameters
@@ -60,9 +66,9 @@ void init_WiFi() {
DEBUG_PRINTF("init_Wifi enabled=%d, apÄ=%d, ssid=%s, password=%s\n", wifi_enabled, wifiap_enabled, ssid.c_str(),
password.c_str());
-#ifdef CUSTOM_HOSTNAME
- WiFi.setHostname(CUSTOM_HOSTNAME); // Set custom hostname if defined in USER_SETTINGS.h
-#endif
+ if (!custom_hostname.empty()) {
+ WiFi.setHostname(custom_hostname.c_str());
+ }
if (wifiap_enabled) {
WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection
@@ -236,9 +242,10 @@ void init_mDNS() {
// e.g batteryemulator8C.local where the mac address is 08:F9:E0:D1:06:8C
String mac = WiFi.macAddress();
String mdnsHost = "batteryemulator" + mac.substring(mac.length() - 2);
-#ifdef CUSTOM_HOSTNAME // If CUSTOM_HOSTNAME is defined, use the same hostname also for mDNS
- mdnsHost = CUSTOM_HOSTNAME;
-#endif
+
+ if (!custom_hostname.empty()) {
+ mdnsHost = String(custom_hostname.c_str());
+ }
// Initialize mDNS .local resolution
if (!MDNS.begin(mdnsHost)) {
diff --git a/Software/src/devboard/wifi/wifi.h b/Software/src/devboard/wifi/wifi.h
index e61a5233..a75ac703 100644
--- a/Software/src/devboard/wifi/wifi.h
+++ b/Software/src/devboard/wifi/wifi.h
@@ -10,6 +10,7 @@ extern std::string password;
extern const uint8_t wifi_channel;
extern std::string ssidAP;
extern std::string passwordAP;
+extern std::string custom_hostname;
void init_WiFi();
void wifi_monitor();