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>
29 lines
634 B
C++
29 lines
634 B
C++
#pragma once
|
|
|
|
#include <cstdlib>
|
|
|
|
namespace kvida {
|
|
|
|
// Minimal '%XX' + '+' decoder for URL-encoded form fields (in place).
|
|
// Shared by commissioning.cpp's Wi-Fi setup form and mqtt.cpp's MQTT
|
|
// settings form.
|
|
inline void url_decode(char *s)
|
|
{
|
|
char *out = s;
|
|
while (*s) {
|
|
if (*s == '+') {
|
|
*out++ = ' ';
|
|
s++;
|
|
} else if (*s == '%' && s[1] && s[2]) {
|
|
const char hex[3] = {s[1], s[2], 0};
|
|
*out++ = static_cast<char>(strtol(hex, nullptr, 16));
|
|
s += 3;
|
|
} else {
|
|
*out++ = *s++;
|
|
}
|
|
}
|
|
*out = '\0';
|
|
}
|
|
|
|
} // namespace kvida
|