ESPHome 2025.12.0
Loading...
Searching...
No Matches
mdns_esp8266.cpp
Go to the documentation of this file.
2#if defined(USE_ESP8266) && defined(USE_ARDUINO) && defined(USE_MDNS)
3
4#include <ESP8266mDNS.h>
8#include "esphome/core/hal.h"
9#include "esphome/core/log.h"
10#include "mdns_component.h"
11
12namespace esphome::mdns {
13
14static void register_esp8266(MDNSComponent *, StaticVector<MDNSService, MDNS_SERVICE_COUNT> &services) {
15 MDNS.begin(App.get_name().c_str());
16
17 for (const auto &service : services) {
18 // Strip the leading underscore from the proto and service_type. While it is
19 // part of the wire protocol to have an underscore, and for example ESP-IDF
20 // expects the underscore to be there, the ESP8266 implementation always adds
21 // the underscore itself.
22 auto *proto = MDNS_STR_ARG(service.proto);
23 while (progmem_read_byte((const uint8_t *) proto) == '_') {
24 proto++;
25 }
26 auto *service_type = MDNS_STR_ARG(service.service_type);
27 while (progmem_read_byte((const uint8_t *) service_type) == '_') {
28 service_type++;
29 }
30 uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
31 MDNS.addService(FPSTR(service_type), FPSTR(proto), port);
32 for (const auto &record : service.txt_records) {
33 MDNS.addServiceTxt(FPSTR(service_type), FPSTR(proto), FPSTR(MDNS_STR_ARG(record.key)),
34 FPSTR(MDNS_STR_ARG(record.value)));
35 }
36 }
37}
38
39void MDNSComponent::setup() { this->setup_buffers_and_register_(register_esp8266); }
40
41void MDNSComponent::loop() { MDNS.update(); }
42
44 MDNS.close();
45 delay(10);
46}
47
48} // namespace esphome::mdns
49
50#endif
const std::string & get_name() const
Get the name of this Application set by pre_setup().
void setup_buffers_and_register_(PlatformRegisterFn platform_register)
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:31
Application App
Global storage of Application pointer - only one Application can exist.
uint8_t progmem_read_byte(const uint8_t *addr)
Definition core.cpp:70