feat(mdns): restore mDNS + hostname kidsOS-XXXX
- Add espressif/mdns 1.3.2 to idf_component.yml + CMake - STA path (esp32_wifi.cpp): set DHCP hostname kidsOS-XXXY from MAC, mdns_init, hostname, instance, _http:80 + _tactility:6666 services - AP path (WebServerService.cpp): same hostname + mDNS for AP mode - Log: mDNS AP/STA initialized hostname 'kidsOS-91ED.local' - Previous implementation from300ddb3alost in driver arch migrationf9453d89(#562 #574) Tested: RLCD 0x2d5470 FLASH_EXIT:0, log shows 'mDNS AP initialized, hostname kidsOS-91ED.local'
This commit is contained in:
@@ -5,9 +5,11 @@
|
||||
#if defined(CONFIG_SOC_WIFI_SUPPORTED) || defined(CONFIG_SLAVE_SOC_WIFI_SUPPORTED)
|
||||
|
||||
#include <esp_event.h>
|
||||
#include <esp_mac.h>
|
||||
#include <esp_netif.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_wifi_default.h>
|
||||
#include <mdns.h>
|
||||
|
||||
#include <tactility/concurrent/mutex.h>
|
||||
#include <tactility/device.h>
|
||||
@@ -151,6 +153,31 @@ error_t bring_up_wifi(Esp32WifiCtx* ctx) {
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
// mDNS + hostname: kidsOS-XXXX from MAC, for Bonjour discovery
|
||||
{
|
||||
uint8_t mac[6];
|
||||
char hostname[32];
|
||||
if (esp_wifi_get_mac(WIFI_IF_STA, mac) == ESP_OK) {
|
||||
snprintf(hostname, sizeof(hostname), "kidsOS-%02X%02X", mac[4], mac[5]);
|
||||
} else {
|
||||
strncpy(hostname, "kidsOS", sizeof(hostname));
|
||||
}
|
||||
LOG_I(TAG, "Setting DHCP hostname to '%s'", hostname);
|
||||
esp_netif_set_hostname(ctx->netif, hostname);
|
||||
|
||||
esp_err_t mdns_err = mdns_init();
|
||||
if (mdns_err == ESP_OK) {
|
||||
LOG_I(TAG, "mDNS initialized, hostname '%s.local'", hostname);
|
||||
mdns_hostname_set(hostname);
|
||||
mdns_instance_name_set("kidsOS Tactility Device");
|
||||
mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);
|
||||
mdns_service_add(NULL, "_tactility", "_tcp", 6666, NULL, 0);
|
||||
} else {
|
||||
LOG_W(TAG, "mDNS init failed: %s", esp_err_to_name(mdns_err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Warning: this is the memory-intensive operation. It uses over 100kB of
|
||||
// RAM with default settings.
|
||||
wifi_init_config_t init_config = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
Reference in New Issue
Block a user