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:
@@ -84,5 +84,6 @@ dependencies:
|
|||||||
version: "1.1.4"
|
version: "1.1.4"
|
||||||
rules:
|
rules:
|
||||||
- if: "target in [esp32s3, esp32p4]"
|
- if: "target in [esp32s3, esp32p4]"
|
||||||
|
espressif/mdns: "1.3.2"
|
||||||
idf: '5.5.2'
|
idf: '5.5.2'
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ idf_component_register(
|
|||||||
SRCS ${SOURCES}
|
SRCS ${SOURCES}
|
||||||
INCLUDE_DIRS "include/"
|
INCLUDE_DIRS "include/"
|
||||||
PRIV_INCLUDE_DIRS "private/"
|
PRIV_INCLUDE_DIRS "private/"
|
||||||
REQUIRES TactilityKernel driver esp_adc esp_driver_i2c esp_lcd vfs fatfs esp_wifi esp_netif esp_event
|
REQUIRES TactilityKernel driver esp_adc esp_driver_i2c esp_lcd vfs fatfs esp_wifi esp_netif esp_event mdns
|
||||||
)
|
)
|
||||||
|
|
||||||
if (DEFINED ENV{ESP_IDF_VERSION})
|
if (DEFINED ENV{ESP_IDF_VERSION})
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
#if defined(CONFIG_SOC_WIFI_SUPPORTED) || defined(CONFIG_SLAVE_SOC_WIFI_SUPPORTED)
|
#if defined(CONFIG_SOC_WIFI_SUPPORTED) || defined(CONFIG_SLAVE_SOC_WIFI_SUPPORTED)
|
||||||
|
|
||||||
#include <esp_event.h>
|
#include <esp_event.h>
|
||||||
|
#include <esp_mac.h>
|
||||||
#include <esp_netif.h>
|
#include <esp_netif.h>
|
||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
#include <esp_wifi_default.h>
|
#include <esp_wifi_default.h>
|
||||||
|
#include <mdns.h>
|
||||||
|
|
||||||
#include <tactility/concurrent/mutex.h>
|
#include <tactility/concurrent/mutex.h>
|
||||||
#include <tactility/device.h>
|
#include <tactility/device.h>
|
||||||
@@ -151,6 +153,31 @@ error_t bring_up_wifi(Esp32WifiCtx* ctx) {
|
|||||||
return ERROR_RESOURCE;
|
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
|
// Warning: this is the memory-intensive operation. It uses over 100kB of
|
||||||
// RAM with default settings.
|
// RAM with default settings.
|
||||||
wifi_init_config_t init_config = WIFI_INIT_CONFIG_DEFAULT();
|
wifi_init_config_t init_config = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ if (DEFINED ENV{ESP_IDF_VERSION})
|
|||||||
vfs
|
vfs
|
||||||
fatfs
|
fatfs
|
||||||
lwip
|
lwip
|
||||||
|
mdns
|
||||||
spi_flash
|
spi_flash
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,8 @@
|
|||||||
#include <esp_system.h>
|
#include <esp_system.h>
|
||||||
#include <esp_vfs_fat.h>
|
#include <esp_vfs_fat.h>
|
||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
|
#include <mdns.h>
|
||||||
|
#include <esp_mac.h>
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
#include <iomanip>
|
#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);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user