ESPHome  2024.3.2
mdns_esp8266.cpp
Go to the documentation of this file.
1 #if defined(USE_ESP8266) && defined(USE_ARDUINO)
2 
3 #include <ESP8266mDNS.h>
6 #include "esphome/core/hal.h"
7 #include "esphome/core/log.h"
8 #include "mdns_component.h"
9 
10 namespace esphome {
11 namespace mdns {
12 
13 void MDNSComponent::setup() {
14  this->compile_records_();
15 
16  MDNS.begin(this->hostname_.c_str());
17 
18  for (const auto &service : this->services_) {
19  // Strip the leading underscore from the proto and service_type. While it is
20  // part of the wire protocol to have an underscore, and for example ESP-IDF
21  // expects the underscore to be there, the ESP8266 implementation always adds
22  // the underscore itself.
23  auto *proto = service.proto.c_str();
24  while (*proto == '_') {
25  proto++;
26  }
27  auto *service_type = service.service_type.c_str();
28  while (*service_type == '_') {
29  service_type++;
30  }
31  MDNS.addService(service_type, proto, service.port);
32  for (const auto &record : service.txt_records) {
33  MDNS.addServiceTxt(service_type, proto, record.key.c_str(), record.value.c_str());
34  }
35  }
36 }
37 
38 void MDNSComponent::loop() { MDNS.update(); }
39 
41  MDNS.close();
42  delay(10);
43 }
44 
45 } // namespace mdns
46 } // namespace esphome
47 
48 #endif
std::vector< MDNSService > services_
void on_shutdown() override
Definition: mdns_esp32.cpp:51
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26