ESPHome  2024.7.2
mdns_component.h
Go to the documentation of this file.
1 #pragma once
2 #include "esphome/core/defines.h"
3 #ifdef USE_MDNS
4 #include <string>
5 #include <vector>
7 
8 namespace esphome {
9 namespace mdns {
10 
11 struct MDNSTXTRecord {
12  std::string key;
13  std::string value;
14 };
15 
16 struct MDNSService {
17  // service name _including_ underscore character prefix
18  // as defined in RFC6763 Section 7
19  std::string service_type;
20  // second label indicating protocol _including_ underscore character prefix
21  // as defined in RFC6763 Section 7, like "_tcp" or "_udp"
22  std::string proto;
23  uint16_t port;
24  std::vector<MDNSTXTRecord> txt_records;
25 };
26 
27 class MDNSComponent : public Component {
28  public:
29  void setup() override;
30  void dump_config() override;
31 
32 #if (defined(USE_ESP8266) || defined(USE_RP2040)) && defined(USE_ARDUINO)
33  void loop() override;
34 #endif
35  float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
36 
37  void add_extra_service(MDNSService service) { services_extra_.push_back(std::move(service)); }
38 
39  void on_shutdown() override;
40 
41  protected:
42  std::vector<MDNSService> services_extra_{};
43  std::vector<MDNSService> services_{};
44  std::string hostname_;
45  void compile_records_();
46 };
47 
48 } // namespace mdns
49 } // namespace esphome
50 #endif
void setup()
void loop()
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
Definition: component.cpp:26
std::vector< MDNSTXTRecord > txt_records
float get_setup_priority() const override
void add_extra_service(MDNSService service)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7