Add configurable Wi-Fi station mDNS hostname support. Mini-Feature #1

This commit is contained in:
2026-08-31 04:14:38 +02:00
parent 06bf33b3cf
commit 3feb3b5916
17 changed files with 589 additions and 12 deletions
+27
View File
@@ -17,6 +17,7 @@
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "mdns_service.h"
#define WIFI_MANAGER_QUEUE_LENGTH 16U
#define WIFI_MANAGER_TASK_STACK_SIZE 6144U
@@ -35,6 +36,7 @@ typedef enum {
MESSAGE_COMMAND_APPLY,
MESSAGE_COMMAND_RECONNECT,
MESSAGE_COMMAND_NEXT_PROFILE,
MESSAGE_COMMAND_MDNS_REANNOUNCE,
MESSAGE_STA_CONNECTED,
MESSAGE_STA_DISCONNECTED,
MESSAGE_STA_GOT_IP,
@@ -109,6 +111,15 @@ static void manager_task(void *context);
static void start_profile_cycle(manager_runtime_t *runtime);
static void start_next_profile(manager_runtime_t *runtime);
static void start_mdns_announcement(void)
{
esp_err_t error = mdns_service_start();
if (error != ESP_OK) {
/* Name discovery is optional; never make network or serial recovery depend on it. */
ESP_LOGW(TAG, "mDNS announcement unavailable: %s", esp_err_to_name(error));
}
}
static void lock_shared(void)
{
(void)xSemaphoreTake(s_mutex, portMAX_DELAY);
@@ -410,6 +421,7 @@ static void mark_intentional_disconnect(manager_runtime_t *runtime)
static void stop_radio(manager_runtime_t *runtime)
{
mdns_service_stop();
if (!runtime->radio_started) {
return;
}
@@ -744,6 +756,7 @@ static void handle_got_ip(manager_runtime_t *runtime,
unlock_shared();
wifi_config_secure_wipe(&config, sizeof(config));
start_mdns_announcement();
}
static void handle_sta_disconnected(manager_runtime_t *runtime,
@@ -764,6 +777,7 @@ static void handle_sta_disconnected(manager_runtime_t *runtime,
bool had_attempt = runtime->attempt_deadline != 0;
bool was_online = runtime->online;
mdns_service_stop();
runtime->associated = false;
runtime->online = false;
runtime->attempt_deadline = 0;
@@ -868,6 +882,13 @@ static void handle_message(manager_runtime_t *runtime,
}
break;
case MESSAGE_COMMAND_MDNS_REANNOUNCE:
if (runtime->online) {
mdns_service_stop();
start_mdns_announcement();
}
break;
case MESSAGE_STA_CONNECTED:
if (!manager_is_started() ||
!connected_event_matches_active_profile(message)) {
@@ -900,6 +921,7 @@ static void handle_message(manager_runtime_t *runtime,
/* Ignore a delayed loss event after a newer DHCP lease. */
break;
}
mdns_service_stop();
runtime->online = false;
runtime->stable_deadline = 0;
runtime->attempt_deadline = esp_timer_get_time() + WIFI_MANAGER_ATTEMPT_US;
@@ -1465,6 +1487,11 @@ esp_err_t wifi_manager_next_profile(void)
return enqueue_lifecycle_command(MESSAGE_COMMAND_NEXT_PROFILE, -1);
}
esp_err_t wifi_manager_mdns_reannounce(void)
{
return enqueue_lifecycle_command(MESSAGE_COMMAND_MDNS_REANNOUNCE, -1);
}
esp_err_t wifi_manager_get_snapshot(wifi_manager_snapshot_t *snapshot)
{
if (snapshot == NULL) {