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:
@@ -46,6 +46,8 @@
|
||||
#include <esp_system.h>
|
||||
#include <esp_vfs_fat.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <mdns.h>
|
||||
#include <esp_mac.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <iomanip>
|
||||
@@ -392,6 +394,27 @@ bool WebServerService::startApMode() {
|
||||
}
|
||||
|
||||
LOG_I(TAG, "WiFi AP started - SSID: '%s', Channel: %u, IP: 192.168.4.1", settings.apSsid.c_str(), (unsigned)settings.apChannel);
|
||||
|
||||
// mDNS for AP mode too - kidsOS-XXXX.local
|
||||
{
|
||||
uint8_t mac[6];
|
||||
char hostname[32];
|
||||
if (esp_wifi_get_mac(WIFI_IF_AP, mac) == ESP_OK) {
|
||||
snprintf(hostname, sizeof(hostname), "kidsOS-%02X%02X", mac[4], mac[5]);
|
||||
} else {
|
||||
strncpy(hostname, "kidsOS", sizeof(hostname));
|
||||
}
|
||||
esp_netif_set_hostname(apNetif, hostname);
|
||||
esp_err_t mdns_err = mdns_init();
|
||||
if (mdns_err == ESP_OK) {
|
||||
LOG_I(TAG, "mDNS AP 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);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user