refactor: entkopple mDNS-Discovery, Status-Flags und WiFi-Manager

- net_mdns: Autostart + Discovery-Retry stabilisiert (Forward-Declarations, Task-Start bei GOT_IP)
- sys_status: EventGroup zentralisiert; Statusbits nicht mehr aus net_mdns gesetzt
- main: Integration von net_mdns Autostart/Discovery und UI-Status-Update vorbereitet
- wifi_mgr: mDNS-Discovery-Logik entfernt/vereinheitlicht, damit keine doppelte Discovery läuft
- net_influx: Anpassungen an neue Discovery/Storage-Semantik
This commit is contained in:
2026-01-22 13:45:15 +01:00
parent ca8ec3c993
commit 2352075c58
8 changed files with 493 additions and 154 deletions
+54 -1
View File
@@ -45,6 +45,10 @@
#include "dns_captive.h"
#include "http_portal.h"
#include "net_mdns.h"
#include "esp_timer.h"
// --- Callback-Implementierungen für das Portal ---
static bool app_load_sta_creds(char **ssid, char **pass)
@@ -150,6 +154,26 @@ static lv_indev_t *lvgl_touch_indev = NULL;
/* --- Button Handle global halten, falls benötigt --- */
static button_handle_t g_btn = NULL;
static void app_update_mdns_influx_status(void)
{
char *url = NULL;
// Ich kenne deine exakte storage-API nicht – bitte eine vorhandene Funktion nutzen:
// Beispiele: storage_load_service_url(&url) oder storage_get_service_url(&url)
// -> Nimm die, die bei dir existiert.
bool ok = storage_load_service_url(&url); // <- ggf. Namen anpassen
if (ok && url && url[0]) {
sys_status_set_mdns_ok(true);
sys_status_set_influx_ok(true);
} else {
sys_status_set_mdns_ok(false);
sys_status_set_influx_ok(false);
}
if (url) free(url);
}
/* Vorwärtsdeklarationen */
void lv_fs_fatfs_init(void);
static esp_err_t app_lvgl_init(void);
@@ -223,6 +247,9 @@ static esp_err_t app_lvgl_init(void)
static void ui_tick_cb(lv_timer_t *t) {
(void)t;
app_update_mdns_influx_status(); // <<< NEU
if (lvgl_port_lock(0)) {
ui_update_status_icons();
tick_screen(0);
@@ -335,6 +362,7 @@ static void button_init(void)
/* ==================== main ==================== */
void app_main(void)
{
/*
esp_log_level_set("storage", ESP_LOG_NONE);
esp_log_level_set("*", ESP_LOG_NONE);
@@ -343,7 +371,7 @@ void app_main(void)
sys_status_set_wifi_ok(false);
sys_status_set_influx_ok(false);
sys_status_set_mdns_ok(false);
*/
// NVS zuerst
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -393,6 +421,31 @@ void app_main(void)
// WiFi AP+STA starten
wifi_mgr_start();
// --- mDNS: Autostart (startet bei STA_GOT_IP automatisch) ---
ESP_ERROR_CHECK(net_mdns_autostart_init(NULL, NULL));
// --- mDNS: Service-Discovery mit Retry (ersetzt mdns_discover_task in wifi_mgr) ---
net_mdns_discover_cfg_t mdns_cfg = {
.service = "_influxdb2",
.proto = "_tcp",
.enforce_port = 8086,
.fallback_service = "_http",
.fallback_proto = "_tcp",
.fallback_port = 8086,
.txt_key = NULL,
.txt_value = NULL,
.query_timeout_ms = 2000,
.retry_interval_ms = 60000,
.max_results = 5,
.instance_prefix = NULL,
.require_instance_prefix = false
};
ESP_ERROR_CHECK(net_mdns_autodiscover_start(&mdns_cfg));
// AP-Netif an DNS weitergeben
dns_captive_set_ap_netif(wifi_mgr_get_ap_netif());
// Captive-DNS starten