ESPHome  2024.10.3
mdns_rp2040.cpp
Go to the documentation of this file.
1 #include "esphome/core/defines.h"
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 
11 namespace esphome {
12 namespace mdns {
13 
14 void MDNSComponent::setup() {
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 = service.proto.c_str();
25  while (*proto == '_') {
26  proto++;
27  }
28  auto *service_type = service.service_type.c_str();
29  while (*service_type == '_') {
30  service_type++;
31  }
32  MDNS.addService(service_type, proto, service.port);
33  for (const auto &record : service.txt_records) {
34  MDNS.addServiceTxt(service_type, proto, record.key.c_str(), record.value.c_str());
35  }
36  }
37 }
38 
39 void MDNSComponent::loop() { MDNS.update(); }
40 
42  MDNS.close();
43  delay(40);
44 }
45 
46 } // namespace mdns
47 } // namespace esphome
48 
49 #endif
std::vector< MDNSService > services_
void on_shutdown() override
Definition: mdns_esp32.cpp:52
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26