From cb3a06382e9aaf5ad9fb313a64dd8bf4262b6473 Mon Sep 17 00:00:00 2001 From: Vitali Date: Fri, 17 Jul 2026 20:41:30 +0700 Subject: [PATCH] feat: Wi-Fi provisioning via WiFiManager captive portal Co-Authored-By: Claude Opus 4.8 --- WeatherPredictor/WeatherPredictor.ino | 8 ++++++++ WeatherPredictor/net.cpp | 14 ++++++++++++++ WeatherPredictor/net.h | 6 ++++++ 3 files changed, 28 insertions(+) create mode 100644 WeatherPredictor/net.cpp create mode 100644 WeatherPredictor/net.h diff --git a/WeatherPredictor/WeatherPredictor.ino b/WeatherPredictor/WeatherPredictor.ino index 238adb4..2da42db 100644 --- a/WeatherPredictor/WeatherPredictor.ino +++ b/WeatherPredictor/WeatherPredictor.ino @@ -7,6 +7,7 @@ #include "forecast.h" #include "history.h" #include "app_settings.h" +#include "net.h" #include "state.h" AppState g_state; @@ -51,6 +52,13 @@ void setup() { historyLoad(); // restore prior samples (empty on first ever boot) Serial.printf("history restored: %d samples\n", historyCount()); + displaySplash("WiFi", "Connect / portal"); + if (netBegin()) { + Serial.printf("WiFi connected: %s\n", netIP().c_str()); + } else { + Serial.println(F("WiFi not connected - running offline")); + } + // Seed first sample immediately. sampleNow(); historyAdd(rtcEpoch(), g_state.mslHpa, g_state.tempC); diff --git a/WeatherPredictor/net.cpp b/WeatherPredictor/net.cpp new file mode 100644 index 0000000..36bfb5c --- /dev/null +++ b/WeatherPredictor/net.cpp @@ -0,0 +1,14 @@ +#include +#include +#include "config.h" +#include "net.h" + +bool netBegin() { + WiFiManager wm; + wm.setConfigPortalTimeout(180); // give up portal after 3 min, run offline + bool ok = wm.autoConnect(AP_NAME); // opens AP "WeatherPredictor-Setup" if no creds + return ok; +} + +bool netConnected() { return WiFi.status() == WL_CONNECTED; } +String netIP() { return WiFi.localIP().toString(); } diff --git a/WeatherPredictor/net.h b/WeatherPredictor/net.h new file mode 100644 index 0000000..5f5a96d --- /dev/null +++ b/WeatherPredictor/net.h @@ -0,0 +1,6 @@ +#pragma once +#include + +bool netBegin(); +bool netConnected(); +String netIP();