ESPHome  2024.12.2
mdns_libretiny.cpp
Go to the documentation of this file.
1 #include "esphome/core/defines.h"
2 #if defined(USE_LIBRETINY) && defined(USE_MDNS)
3 
6 #include "esphome/core/log.h"
7 #include "mdns_component.h"
8 
9 #include <mDNS.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 
40 
41 } // namespace mdns
42 } // namespace esphome
43 
44 #endif
std::vector< MDNSService > services_
void on_shutdown() override
Definition: mdns_esp32.cpp:52
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7