DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
mdns_service.h
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.h
6 * @brief Optional mDNS / DNS-SD advertisement (DETWS_ENABLE_MDNS).
7 *
8 * Thin wrapper over the ESP-IDF `mdns` component so a headless device is reachable
9 * at `<hostname>.local` and advertises an `_http._tcp` service for browsers and
10 * Bonjour / DNS-SD tools (with optional TXT records and extra service types).
11 * Compiled to a no-op stub when DETWS_ENABLE_MDNS is 0 or on non-Arduino builds,
12 * so it costs nothing unless enabled.
13 *
14 * @author Douglas Quigg (dstroy0)
15 * @date 2026
16 */
17
18#ifndef DETERMINISTICESPASYNCWEBSERVER_MDNS_SERVICE_H
19#define DETERMINISTICESPASYNCWEBSERVER_MDNS_SERVICE_H
20
21#include "ServerConfig.h"
22#include <stdint.h>
23
24/**
25 * @brief Start mDNS responder and advertise an HTTP service.
26 *
27 * Call once after the WiFi link is up (wifi_ready()) and after begin(). The
28 * device becomes reachable at `<hostname>.local` and advertises
29 * `_http._tcp` on @p http_port.
30 *
31 * @param hostname Host label without the `.local` suffix (e.g. "mydevice").
32 * @param http_port TCP port the HTTP server listens on (default 80).
33 * @return true if the responder started; false if disabled at compile time,
34 * not on Arduino, or the mdns component failed to start.
35 */
36bool detws_mdns_begin(const char *hostname, uint16_t http_port = 80);
37
38/**
39 * @brief Add a TXT key/value record to the advertised `_http._tcp` service.
40 *
41 * Bonjour / DNS-SD browsers display these (e.g. `"path"`=`"/"`, `"fw"`=`"1.2.3"`).
42 * Call after detws_mdns_begin().
43 *
44 * @return true on success; false if mDNS is disabled or not running.
45 */
46bool detws_mdns_txt(const char *key, const char *value);
47
48/**
49 * @brief Advertise an additional service, e.g. `("_https", "_tcp", 443)`.
50 *
51 * @param service_type DNS-SD service type, e.g. `"_https"`.
52 * @param proto `"_tcp"` or `"_udp"`.
53 * @param port TCP/UDP port the service listens on.
54 * @return true on success; false if mDNS is disabled or not running.
55 */
56bool detws_mdns_add_service(const char *service_type, const char *proto, uint16_t port);
57
58#endif // DETERMINISTICESPASYNCWEBSERVER_MDNS_SERVICE_H
User-facing configuration for DeterministicESPAsyncWebServer.
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).
bool detws_mdns_begin(const char *hostname, uint16_t http_port=80)
Start mDNS responder and advertise an HTTP service.