DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
mdns_service.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file mdns_service.cpp
6 * @brief mDNS / DNS-SD advertisement implementation (DETWS_ENABLE_MDNS).
7 *
8 * Uses the ESP-IDF `mdns` component directly (not the Arduino ESPmDNS wrapper)
9 * so the only external dependency stays the base SDK + mbedTLS.
10 */
11
12#include "mdns_service.h"
13
14#if DETWS_ENABLE_MDNS && defined(ARDUINO)
15
16#include "mdns.h"
17
18bool detws_mdns_begin(const char *hostname, uint16_t http_port)
19{
20 if (!hostname || hostname[0] == '\0')
21 return false;
22 if (mdns_init() != ESP_OK)
23 return false;
24 if (mdns_hostname_set(hostname) != ESP_OK)
25 return false;
26 // Advertise an HTTP service so browsers / DNS-SD tools discover the device.
27 mdns_service_add(nullptr, "_http", "_tcp", http_port, nullptr, 0);
28 return true;
29}
30
31bool detws_mdns_txt(const char *key, const char *value)
32{
33 if (!key || !value)
34 return false;
35 // Attach a TXT key/value to the _http._tcp service (Bonjour browsers show it).
36 return mdns_service_txt_item_set("_http", "_tcp", key, value) == ESP_OK;
37}
38
39bool detws_mdns_add_service(const char *service_type, const char *proto, uint16_t port)
40{
41 if (!service_type || !proto)
42 return false;
43 // Advertise an additional service, e.g. ("_https", "_tcp", 443).
44 return mdns_service_add(nullptr, service_type, proto, port, nullptr, 0) == ESP_OK;
45}
46
47#else
48
49bool detws_mdns_begin(const char *hostname, uint16_t http_port)
50{
51 (void)hostname;
52 (void)http_port;
53 return false; // mDNS disabled at compile time (or non-Arduino build)
54}
55
56#endif // DETWS_ENABLE_MDNS && ARDUINO
bool detws_mdns_begin(const char *hostname, uint16_t http_port)
Start mDNS responder and advertise an HTTP service.
Optional mDNS / DNS-SD advertisement (DETWS_ENABLE_MDNS).
bool detws_mdns_txt(const char *key, const char *value)
Add a TXT key/value record to the advertised _http._tcp service.
bool detws_mdns_add_service(const char *service_type, const char *proto, uint16_t port)
Advertise an additional service, e.g. ("_https", "_tcp", 443).