adds mdns support

This commit is contained in:
Shawn A
2018-02-23 23:28:19 -06:00
parent 327db84d18
commit f210000c94
2 changed files with 28 additions and 5 deletions
+16 -3
View File
@@ -193,13 +193,26 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
// set hostname before stating
if((String)_hostname != ""){
DEBUG_WM("Setting hostname:",_hostname);
bool res = true;
#ifdef ESP8266
res = WiFi.hostname(_hostname);
#ifdef ESP8266MDNS_H
DEBUG_WM("Setting MDNS hostname");
if(MDNS.begin(_hostname)){
MDNS.addService("http", "tcp", 80);
}
#endif
#elif defined(ESP32)
// @note hostname must be set after STA_START
delay(200); // do not remove, give time for STA_START
res = WiFi.setHostname(_hostname);
#ifdef ESP32MDNS_H
DEBUG_WM("Setting MDNS hostname");
if(MDNS.begin(_hostname)){
MDNS.addService("http", "tcp", 80);
}
#endif
#endif
if(!res)DEBUG_WM(F("hostname: set failed!"));
@@ -1990,10 +2003,10 @@ bool WiFiManager::WiFi_enableSTA(bool enable) {
bool WiFiManager::WiFi_eraseConfig(void) {
#ifdef ESP8266
#ifndef FIXERASECONFIG
#ifndef WM_FIXERASECONFIG
return ESP.eraseConfig();
#else
// erase config BUG polyfill
#else
// erase config BUG replacement
// https://github.com/esp8266/Arduino/pull/3635
const size_t cfgSize = 0x4000;
size_t cfgAddr = ESP.getFlashChipSize() - cfgSize;
+12 -2
View File
@@ -13,7 +13,9 @@
#ifndef WiFiManager_h
#define WiFiManager_h
#define WEBSERVERSHIM // use webserver shim lib
#define WM_WEBSERVERSHIM // use webserver shim lib
// #define WM_MDNS // use MDNS
// #define WM_FIXERASECONFIG // use erase flash fix
#ifdef ESP8266
@@ -23,6 +25,10 @@
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#ifdef WM_MDNS
#include <ESP8266mDNS.h>
#endif
#define WIFI_getChipId() ESP.getChipId()
#define WIFI_AUTH_OPEN ENC_TYPE_NONE
@@ -36,7 +42,7 @@
#ifndef WEBSERVER_H
#warning "WEBSERVER not implemented in espressif/esp32, see readme notes"
#ifdef WEBSERVERSHIM
#ifdef WM_WEBSERVERSHIM
#include <WebServer.h>
#else
#include <ESP8266WebServer.h>
@@ -45,6 +51,9 @@
#endif
#endif
#ifdef WM_MDNS
#include <ESPmDNS.h>
#endif
#else
#endif
@@ -222,6 +231,7 @@ class WiFiManager
// defaults
const byte DNS_PORT = 53;
const byte HTTP_PORT = 80;
String _apName = "no-net";
String _apPassword = "";
String _ssid = "";