ESPHome 2025.12.3
Loading...
Searching...
No Matches
mdns_libretiny.cpp
Go to the documentation of this file.
2#if defined(USE_LIBRETINY) && defined(USE_MDNS)
3
7#include "esphome/core/log.h"
8#include "mdns_component.h"
9
10#include <mDNS.h>
11
12namespace esphome::mdns {
13
14static void register_libretiny(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_libretiny); }
39
41
42} // namespace esphome::mdns
43
44#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)
Application App
Global storage of Application pointer - only one Application can exist.