Add MQTT client + Home Assistant Discovery, verified end-to-end
Adds espressif/mqtt and mdns as the project's first external managed component dependencies (neither ships with ESP-IDF core in v6.0.2 anymore). Once Wi-Fi connects, the device advertises itself on the LAN as kvida-xxxxxx.local and serves a persistent settings page there for MQTT broker host/port and credentials -- the ongoing config channel beyond the one-time Wi-Fi captive portal. mDNS auto-discovery of _mqtt._tcp was the original plan, but verified against a real Home Assistant OS + Mosquitto add-on that it doesn't reliably answer PTR queries on the LAN (confirmed with a raw mDNS query from the host, parsed properly with dnspython after an earlier naive byte-check gave a false positive). Manual host/port entry is now the primary path; mDNS discovery still runs as a secondary fallback attempt, retried every 30s, in case it works on other networks. On MQTT_EVENT_CONNECTED, publishes retained HA MQTT Discovery for a diagnostic "connectivity" binary_sensor (grouped under a Kvida/Xylon device block) plus an online/offline availability topic driven by MQTT's own LWT. Verified end-to-end on real hardware: the device appears in Home Assistant with a "Connected" Connectivity sensor. Also extracts url_decode() (previously local to commissioning.cpp) and a new device_id() helper into shared headers, since both commissioning's Wi-Fi form and the new MQTT settings form need them. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
idf_component_register(
|
||||
SRCS "src/commissioning.cpp" "src/dns_server.c"
|
||||
SRCS "src/commissioning.cpp" "src/dns_server.c" "src/mqtt.cpp"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "src"
|
||||
PRIV_REQUIRES esp_wifi esp_netif esp_event esp_http_server esp_timer nvs_flash
|
||||
PRIV_REQUIRES esp_wifi esp_netif esp_event esp_http_server esp_timer nvs_flash espressif__mqtt espressif__mdns
|
||||
EMBED_FILES "src/portal.html"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user