diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h
index 9c64a5e5..95315797 100644
--- a/Software/USER_SETTINGS.h
+++ b/Software/USER_SETTINGS.h
@@ -119,6 +119,8 @@
/* Connectivity options */
#define WIFI
//#define WIFICONFIG //Enable this line to set a static IP address / gateway /subnet mask for the device. see USER_SETTINGS.cpp for the settings
+//#define CUSTOM_HOSTNAME \
+ "battery-emulator" //Enable this line to use a custom hostname for the device, if disabled the default naming format 'esp32-XXXXXX' will be used.
#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings.
#define WIFIAP //When enabled, the emulator will broadcast its own access point Wifi. Can be used at the same time as a normal Wifi connection to a router.
#define MDNSRESPONDER //Enable this line to enable MDNS, allows battery monitor te be found by .local address. Requires WEBSERVER to be enabled.
diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp
index 09b6db98..0e3517b6 100644
--- a/Software/src/devboard/webserver/webserver.cpp
+++ b/Software/src/devboard/webserver/webserver.cpp
@@ -1008,6 +1008,7 @@ String processor(const String& var) {
}
content += "";
if (status == WL_CONNECTED) {
+ content += "
Hostname: " + String(WiFi.getHostname()) + "
";
content += "IP: " + WiFi.localIP().toString() + "
";
} else {
content += "Wifi state: " + getConnectResultString(status) + "
";
diff --git a/Software/src/devboard/wifi/wifi.cpp b/Software/src/devboard/wifi/wifi.cpp
index 0d18ba12..b671af8b 100644
--- a/Software/src/devboard/wifi/wifi.cpp
+++ b/Software/src/devboard/wifi/wifi.cpp
@@ -28,6 +28,10 @@ static bool connected_once = false;
void init_WiFi() {
+#ifdef CUSTOM_HOSTNAME
+ WiFi.setHostname(CUSTOM_HOSTNAME); // Set custom hostname if defined in USER_SETTINGS.h
+#endif
+
#ifdef WIFIAP
WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection
init_WiFi_AP();
@@ -182,6 +186,9 @@ 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
// Initialize mDNS .local resolution
if (!MDNS.begin(mdnsHost)) {
@@ -190,7 +197,7 @@ void init_mDNS() {
#endif
} else {
// Advertise via bonjour the service so we can auto discover these battery emulators on the local network.
- MDNS.addService("battery_emulator", "tcp", 80);
+ MDNS.addService(mdnsHost, "tcp", 80);
}
}
#endif // MDNSRESPONDER