feat(webconfig): implement web configuration portal for ESP32

This commit is contained in:
agessaman
2026-07-16 17:00:22 -07:00
parent d7a7e1b642
commit dfee21a0c9
16 changed files with 2460 additions and 3 deletions
+47
View File
@@ -8,6 +8,7 @@
#ifdef WITH_MQTT_BRIDGE
#include <WiFi.h>
#include <helpers/esp32/WebConfigServer.h> // defines WITH_WEBCONFIG on ESP32
#endif
#define AUTO_OFF_MILLIS 20000 // 20 seconds
@@ -77,6 +78,43 @@ void UITask::renderCurrScreen() {
_display->setCursor((_display->width() - typeWidth) / 2, 48);
_display->print(node_type);
} else { // home screen
#ifdef WITH_WEBCONFIG
if (WebConfigServer::isRebootPending()) {
// save confirmed on-device: show ground truth even if the browser
// lost its connection before the confirmation reached it
_display->setTextSize(1);
_display->setColor(DisplayDriver::GREEN);
_display->setCursor(0, 14);
_display->print("Config saved!");
_display->setColor(DisplayDriver::LIGHT);
_display->setCursor(0, 30);
_display->print("Rebooting...");
return;
}
char wc_ssid[33], wc_ip[16];
if (WebConfigServer::getSetupInfo(wc_ssid, sizeof(wc_ssid), wc_ip, sizeof(wc_ip))) {
// setup portal active: show join instructions instead of the home screen
_display->setTextSize(1);
_display->setColor(DisplayDriver::GREEN);
_display->setCursor(0, 0);
_display->print("Observer WiFi Setup");
_display->setColor(DisplayDriver::LIGHT);
_display->setCursor(0, 14);
_display->print("Join WiFi:");
_display->setColor(DisplayDriver::YELLOW);
_display->setCursor(6, 24);
_display->print(wc_ssid);
_display->setColor(DisplayDriver::LIGHT);
_display->setCursor(0, 40);
_display->print("Then browse to:");
_display->setColor(DisplayDriver::YELLOW);
_display->setCursor(6, 50);
_display->print(wc_ip);
return;
}
#endif
// node name
_display->setCursor(0, 0);
_display->setTextSize(1);
@@ -126,6 +164,15 @@ void UITask::loop() {
}
#endif
#ifdef WITH_WEBCONFIG
// While the setup portal is up there's no user button to wake the screen
// reliably - keep it on so the join instructions stay visible.
if (WebConfigServer::getSetupInfo(NULL, 0, NULL, 0)) {
if (!_display->isOn()) _display->turnOn();
_auto_off = millis() + AUTO_OFF_MILLIS;
}
#endif
if (_display->isOn()) {
if (millis() >= _next_refresh) {
_display->startFrame();