mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
Add feature to set a custom device hostname
This commit is contained in:
parent
f94a011063
commit
daeeece63a
5 changed files with 12 additions and 1 deletions
|
@ -28,6 +28,10 @@ static bool connected_once = false;
|
|||
|
||||
void init_WiFi() {
|
||||
|
||||
#ifdef HOSTNAME
|
||||
WiFi.setHostname(hostname);
|
||||
#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 HOSTNAME // If HOSTNAME is defined, use the same hostname from USER_SETTINGS.h also for mDNS
|
||||
mdnsHost = 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue