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();