ESPHome  2022.12.8
mdns_rp2040.cpp
Go to the documentation of this file.
1 #ifdef USE_RP2040
2 
5 #include "esphome/core/log.h"
6 #include "mdns_component.h"
7 
8 #include <ESP8266mDNS.h>
9 
10 namespace esphome {
11 namespace mdns {
12 
13 void MDNSComponent::setup() {
14  this->compile_records_();
15 
16  network::IPAddress addr = network::get_ip_address();
17  MDNS.begin(this->hostname_.c_str(), (uint32_t) addr);
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 
41 } // namespace mdns
42 } // namespace esphome
43 
44 #endif
std::vector< MDNSService > services_
Definition: a4988.cpp:4
network::IPAddress get_ip_address()
Definition: util.cpp:29