Skip to content

File espos_mdns.h

FileList > espos_net > include > espos_mdns.h

Go to the source code of this file

  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>
  • #include "esp_err.h"

Public Functions

Type Name
esp_err_t espos_mdns_add_service (const char * type, const char * proto, uint16_t port, const char *const * txt_kv, size_t n_txt)
Advertise type .
bool espos_mdns_is_ready (void)
True while the responder runs and the default route is up: a query (mdns_query_ptr) or an announcement can reach the network.
esp_err_t espos_mdns_remove_service (const char * type, const char * proto)
Withdraw a service added with espos_mdns_add_service() .
esp_err_t espos_mdns_start (void)
Bring the responder up: hostname, instance name, the built-in services above, then every service queued with espos_mdns_add_service() .

Macros

Type Name
define ESPOS_MDNS_PROTO_MAX 8 /\* "\_tcp" \| "\_udp" \*/
define ESPOS_MDNS_TXT_MAX_BYTES 256 /\* all keys + values of one service, NULs included \*/
define ESPOS_MDNS_TXT_MAX_ITEMS 8 /\* "k=v" items per service \*/
define ESPOS_MDNS_TYPE_MAX 32 /\* service type incl. NUL: "\_signalk-player" \*/

Public Functions Documentation

function espos_mdns_add_service

Advertise type .

esp_err_t espos_mdns_add_service (
    const char * type,
    const char * proto,
    uint16_t port,
    const char *const * txt_kv,
    size_t n_txt
) 

proto (e.g. "_signalk-player", "_tcp") on port with the TXT items txt_kv = {"k=v", "flag", ...} (n_txt of them, 0 and NULL for none). Strings are copied. Callable any time: before the responder exists the entry waits in a table of CONFIG_ESPOS_NET_MDNS_MAX_SERVICES slots and is registered by espos_mdns_start(); afterwards it is registered at once. Adding a (type, proto) that is already in the table replaces its port and TXT (the old record is withdrawn, the new one announced).

ESP_ERR_INVALID_ARG for a malformed type/proto/item, ESP_ERR_INVALID_SIZE when the TXT items do not fit the limits above, ESP_ERR_NO_MEM when the table is full, and the responder's own error (also ESP_ERR_NO_MEM once CONFIG_MDNS_MAX_SERVICES is reached) when it refuses the record โ€” in that case the entry is dropped, not queued.


function espos_mdns_is_ready

True while the responder runs and the default route is up: a query (mdns_query_ptr) or an announcement can reach the network.

bool espos_mdns_is_ready (
    void
) 

Drops on ESPOS_EVENT_NETWORK_DOWN. Always false when built without the responder.


function espos_mdns_remove_service

Withdraw a service added with espos_mdns_add_service() .

esp_err_t espos_mdns_remove_service (
    const char * type,
    const char * proto
) 

ESP_ERR_NOT_FOUND when no such (type, proto) was added through this API; the built-in services cannot be removed.


function espos_mdns_start

Bring the responder up: hostname, instance name, the built-in services above, then every service queued with espos_mdns_add_service() .

esp_err_t espos_mdns_start (
    void
) 

Requires espos_net_start() (netif layer, event loop, hostname); ESP_ERR_INVALID_STATE with one log line otherwise. Idempotent. espos_net_start() calls it, so an application never needs to โ€” the call exists for firmware that drives the start sequence by hand.

ESP_ERR_NOT_SUPPORTED when built without CONFIG_ESPOS_NET_MDNS or on the linux target: the device is then not advertised, nothing else is affected.


Macro Definition Documentation

define ESPOS_MDNS_PROTO_MAX

#define ESPOS_MDNS_PROTO_MAX `8    /* "_tcp" | "_udp" */`

define ESPOS_MDNS_TXT_MAX_BYTES

#define ESPOS_MDNS_TXT_MAX_BYTES `256  /* all keys + values of one service, NULs included */`

define ESPOS_MDNS_TXT_MAX_ITEMS

#define ESPOS_MDNS_TXT_MAX_ITEMS `8    /* "k=v" items per service */`

define ESPOS_MDNS_TYPE_MAX

#define ESPOS_MDNS_TYPE_MAX `32   /* service type incl. NUL: "_signalk-player" */`


The documentation for this class was generated from the following file espos_net/include/espos_mdns.h