feat: Wi-Fi provisioning via WiFiManager captive portal
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiManager.h>
|
||||
#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(); }
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
bool netBegin();
|
||||
bool netConnected();
|
||||
String netIP();
|
||||
Reference in New Issue
Block a user