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