Skip to content

Commit

Permalink
Added ESPmDNS
Browse files Browse the repository at this point in the history
  • Loading branch information
christianjebauer committed Feb 13, 2024
1 parent c7227bf commit 57d48c5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <WiFi.h>
#include <DNSServer.h>
#include <ESPmDNS.h>
#include <time.h>
#include <ESPAsyncWebServer.h>
#include <WebAuthentication.h> // otherwise the IDE wont find generateDigestHash()
Expand Down Expand Up @@ -269,8 +270,8 @@ bool checkPairingValid() {
bool initWifi() {
// Connect to Wi-Fi
WifiSettings wifiSettings = settingsManager.getWifiSettings();
WiFi.mode(WIFI_STA);
WiFi.setHostname(wifiSettings.hostname.c_str()); //define hostname
WiFi.mode(WIFI_STA);
WiFi.begin(wifiSettings.ssid.c_str(), wifiSettings.password.c_str());
int counter = 0;
while (WiFi.status() != WL_CONNECTED) {
Expand All @@ -290,6 +291,20 @@ bool initWifi() {
notifyClients("Static IP address settings are incomplete. DHCP is used instead.");
}
}


//initialize mDNS service
esp_err_t err = mdns_init();
if (err) {
printf("MDNS Init failed: %d\n", err);
}
//set hostname
mdns_hostname_set(wifiSettings.hostname.c_str());
//set default instance
mdns_instance_name_set(wifiSettings.hostname.c_str());
// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);

Serial.println("Connected!");

// Print ESP32 Local IP Address
Expand Down

0 comments on commit 57d48c5

Please sign in to comment.