ESPHome 2025.10.1
Loading...
Searching...
No Matches
mdns_rp2040.cpp
Go to the documentation of this file.
2#if defined(USE_RP2040) && defined(USE_MDNS)
3
6#include "esphome/core/log.h"
7#include "mdns_component.h"
8
9#include <ESP8266mDNS.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 (*proto == '_') {
26 proto++;
27 }
28 auto *service_type = MDNS_STR_ARG(service.service_type);
29 while (*service_type == '_') {
30 service_type++;
31 }
32 uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
33 MDNS.addService(service_type, proto, port);
34 for (const auto &record : service.txt_records) {
35 MDNS.addServiceTxt(service_type, proto, MDNS_STR_ARG(record.key), MDNS_STR_ARG(record.value));
36 }
37 }
38}
39
40void MDNSComponent::loop() { MDNS.update(); }
41
43 MDNS.close();
44 delay(40);
45}
46
47} // namespace mdns
48} // namespace esphome
49
50#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:29