ESPHome 2025.10.3
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>
7#include "esphome/core/hal.h"
8#include "esphome/core/log.h"
9#include "mdns_component.h"
10
11namespace esphome {
12namespace mdns {
13
15 this->compile_records_();
16
17 MDNS.begin(this->hostname_.c_str());
18
19 for (const auto &service : this->services_) {
20 // Strip the leading underscore from the proto and service_type. While it is
21 // part of the wire protocol to have an underscore, and for example ESP-IDF
22 // expects the underscore to be there, the ESP8266 implementation always adds
23 // the underscore itself.
24 auto *proto = MDNS_STR_ARG(service.proto);
25 while (progmem_read_byte((const uint8_t *) proto) == '_') {
26 proto++;
27 }
28 auto *service_type = MDNS_STR_ARG(service.service_type);
29 while (progmem_read_byte((const uint8_t *) service_type) == '_') {
30 service_type++;
31 }
32 uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
33 MDNS.addService(FPSTR(service_type), FPSTR(proto), port);
34 for (const auto &record : service.txt_records) {
35 MDNS.addServiceTxt(FPSTR(service_type), FPSTR(proto), FPSTR(MDNS_STR_ARG(record.key)),
36 FPSTR(MDNS_STR_ARG(record.value)));
37 }
38 }
39}
40
41void MDNSComponent::loop() { MDNS.update(); }
42
44 MDNS.close();
45 delay(10);
46}
47
48} // namespace mdns
49} // namespace esphome
50
51#endif
StaticVector< MDNSService, MDNS_SERVICE_COUNT > services_
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:30
uint8_t progmem_read_byte(const uint8_t *addr)
Definition core.cpp:69