Step 2a (1/2): mDNS hostname.local and _http._tcp

- aes67_net: espressif/mdns 1.13.1 (managed component, pinned in
  dependencies.lock). Advertises <net.hostname>.local and the web UI as
  _http._tcp port 80. net apply callback renames live.
- First config value actually applied: net.hostname.
- Docs: mDNS in the core Network section; build order gets step 2a
  (mDNS, then LLDP).
- Verified on board: p4-aes67.local resolves via raw mDNS and getent,
  http://p4-aes67.local/ answers, service shows in _http._tcp browse;
  live rename to p4-rename and back works (after ~1 s probing).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-24 23:08:51 +10:00
parent 8e52401e9c
commit 979420a6bb
6 changed files with 54 additions and 3 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
idf_component_register(SRCS "aes67_net.c"
INCLUDE_DIRS "include"
REQUIRES esp_eth esp_netif esp_event
PRIV_REQUIRES aes67_web lwip)
PRIV_REQUIRES aes67_web lwip espressif__mdns)
+29 -2
View File
@@ -10,6 +10,7 @@
#include "esp_event.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "mdns.h"
static const char *TAG = "net";
@@ -105,6 +106,31 @@ static bool inet_validate(const cJSON *g, char *err, size_t n)
check_addr(g, err, n);
}
// mDNS: <hostname>.local plus the web UI as _http._tcp.
static void mdns_setup(void)
{
cJSON *net = cfg_get("net");
const char *host = cJSON_GetObjectItemCaseSensitive(net, "hostname")->valuestring;
esp_err_t err = mdns_init();
if (err == ESP_OK) {
mdns_hostname_set(host);
mdns_instance_name_set(host);
mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);
ESP_LOGI(TAG, "mDNS: %s.local, _http._tcp port 80", host);
} else {
ESP_LOGE(TAG, "mDNS init failed: %s", esp_err_to_name(err));
}
cJSON_Delete(net);
}
static void net_apply(const cJSON *g)
{
const char *host = cJSON_GetObjectItemCaseSensitive(g, "hostname")->valuestring;
if (mdns_hostname_set(host) == ESP_OK && mdns_instance_name_set(host) == ESP_OK) {
ESP_LOGI(TAG, "mDNS: now %s.local", host);
}
}
static void net_status(cJSON *st)
{
char ip[16] = "", mac_s[18] = "";
@@ -126,8 +152,8 @@ static void net_status(cJSON *st)
esp_err_t aes67_net_init(esp_eth_handle_t eth)
{
// Config is stored only for now; applying it (hostname, static IP, VLAN) comes later.
ESP_ERROR_CHECK(cfg_register("net", NET_DEFAULTS, net_validate, NULL));
// Applied so far: hostname (mDNS). Static IP and VLAN come later.
ESP_ERROR_CHECK(cfg_register("net", NET_DEFAULTS, net_validate, net_apply));
ESP_ERROR_CHECK(cfg_register("inet", INET_DEFAULTS, inet_validate, NULL));
ESP_ERROR_CHECK(esp_netif_init());
@@ -143,6 +169,7 @@ esp_err_t aes67_net_init(esp_eth_handle_t eth)
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, ip_event, NULL));
mdns_setup();
status_register(net_status);
return esp_eth_start(eth);
}
+2
View File
@@ -0,0 +1,2 @@
dependencies:
espressif/mdns: "^1.13.1"