ESPHome 2025.12.0-dev
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 {
13namespace mdns {
14
16#ifdef USE_MDNS_STORE_SERVICES
17 this->compile_records_(this->services_);
18 const auto &services = this->services_;
19#else
20 StaticVector<MDNSService, MDNS_SERVICE_COUNT> services;
21 this->compile_records_(services);
22#endif
23
24 MDNS.begin(App.get_name().c_str());
25
26 for (const auto &service : services) {
27 // Strip the leading underscore from the proto and service_type. While it is
28 // part of the wire protocol to have an underscore, and for example ESP-IDF
29 // expects the underscore to be there, the ESP8266 implementation always adds
30 // the underscore itself.
31 auto *proto = MDNS_STR_ARG(service.proto);
32 while (*proto == '_') {
33 proto++;
34 }
35 auto *service_type = MDNS_STR_ARG(service.service_type);
36 while (*service_type == '_') {
37 service_type++;
38 }
39 uint16_t port_ = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
40 MDNS.addService(service_type, proto, port_);
41 for (const auto &record : service.txt_records) {
42 MDNS.addServiceTxt(service_type, proto, MDNS_STR_ARG(record.key), MDNS_STR_ARG(record.value));
43 }
44 }
45}
46
48
49} // namespace mdns
50} // namespace esphome
51
52#endif
const std::string & get_name() const
Get the name of this Application set by pre_setup().
void compile_records_(StaticVector< MDNSService, MDNS_SERVICE_COUNT > &services)
StaticVector< MDNSService, MDNS_SERVICE_COUNT > services_
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
Application App
Global storage of Application pointer - only one Application can exist.