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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user