Added an option to disable mDNS (#1716)
* Added an option to disable mDNS * Fixed linter issues * Moved the enable_mdns option to WiFi and Ethernet components * extracted common method for add mdns library * lint Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
This commit is contained in:
@@ -16,12 +16,14 @@
|
||||
#include "esphome/components/ethernet/ethernet_component.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_MDNS
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <ESPmDNS.h>
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266mDNS.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
||||
@@ -39,7 +41,7 @@ bool network_is_connected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && defined(USE_MDNS)
|
||||
bool mdns_setup;
|
||||
#endif
|
||||
|
||||
@@ -47,6 +49,7 @@ bool mdns_setup;
|
||||
static const uint8_t WEBSERVER_PORT = 80;
|
||||
#endif
|
||||
|
||||
#ifdef USE_MDNS
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
void network_setup_mdns(IPAddress address, int interface) {
|
||||
// Latest arduino framework breaks mDNS for AP interface
|
||||
@@ -80,8 +83,10 @@ void network_setup_mdns(IPAddress address, int interface) {
|
||||
MDNS.addService("prometheus-http", "tcp", WEBSERVER_PORT);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void network_tick_mdns() {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && defined(USE_MDNS)
|
||||
if (mdns_setup)
|
||||
MDNS.update();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user