2#if defined(USE_ESP8266) && defined(USE_ARDUINO) && defined(USE_MDNS)
4#include <ESP8266mDNS.h>
21class GuardedMDNSResponder :
public ::esp8266::MDNSImplementation::MDNSResponder {
23 void update_guarded() { this->run_guarded_(&GuardedMDNSResponder::update); }
24 void close_guarded() { this->run_guarded_(&GuardedMDNSResponder::close); }
27 void run_guarded_(
bool (GuardedMDNSResponder::*fn)()) {
28 UdpContext *ctx = this->m_pUDPContext;
37 if (!this->in_loop_call_) {
41 this->in_loop_call_ =
true;
44 while (this->m_pUDPContext !=
nullptr && this->m_pUDPContext->next()) {
45 this->_parseMessage();
47 this->in_loop_call_ =
false;
50 volatile bool in_loop_call_{
false};
53static GuardedMDNSResponder mdns_responder;
55static void register_esp8266(MDNSComponent *, StaticVector<MDNSService, MDNS_SERVICE_COUNT> &services) {
58 for (
const auto &service : services) {
63 auto *proto = MDNS_STR_ARG(service.proto);
67 auto *service_type = MDNS_STR_ARG(service.service_type);
71 uint16_t port = service.port.value();
72 mdns_responder.addService(FPSTR(service_type), FPSTR(proto), port);
73 for (
const auto &record : service.txt_records) {
74 mdns_responder.addServiceTxt(FPSTR(service_type), FPSTR(proto), FPSTR(MDNS_STR_ARG(record.key)),
75 FPSTR(MDNS_STR_ARG(record.value)));
80#ifdef USE_MDNS_EVENT_DRIVEN_POLLING
84#ifdef USE_MDNS_WIFI_LISTENER
91 if (wifi->is_roaming() || (!wifi->is_connected() && !wifi->is_ap_active()))
94 mdns_responder.update_guarded();
102#ifdef USE_MDNS_WIFI_LISTENER
111#ifdef USE_MDNS_WIFI_LISTENER
116 if (ips[0].is_set()) {
123 mdns_responder.close_guarded();
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
bool cancel_interval(const char *name)
Cancel an interval function.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void set_interval(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a const char* name.
constexpr const char * c_str() const
void on_shutdown() override
static constexpr uint32_t MDNS_POLL_STOP_ID
void start_polling_window_()
Arm a fresh MDNS_POLL_WINDOW_MS polling window.
void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1, const network::IPAddress &dns2) override
static constexpr uint32_t MDNS_POLL_WINDOW_MS
void setup_buffers_and_register_(PlatformRegisterFn platform_register)
static constexpr uint32_t MDNS_POLL_ID
static constexpr uint32_t MDNS_UPDATE_INTERVAL_MS
void add_ip_state_listener(WiFiIPStateListener *listener)
Add a listener for IP state changes.
std::array< IPAddress, 5 > IPAddresses
WiFiComponent * global_wifi_component
void HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.
uint8_t progmem_read_byte(const uint8_t *addr)