Public Access
M1 step 2: Wi-Fi Service, Saved Networks, NTP, Settings page
- lib/wifi (host-tested): SavedNetworks (up to 8, validated, hidden flag, persisted) and WifiController (joins the strongest Saved Network, tries hidden ones in turn, backoff 10/30/60 s, connect timeout, Monitoring override, radio off without Saved Networks) - WifiService carries out the controller's actions, sets the EU country code, and syncs the Clock over SNTP without touching the TZ - Wi-Fi On/Off setting; Settings > Wi-Fi page: status, add from a scan or a hidden network, forget - Status Bar: W + signal bars, W? while searching, MON while monitoring - Serial: wifi add / wifi status (replaces the step 1 heap probe) Verified on the device: joins the test network ~5 s after boot, clock set over NTP, ~129 KB free heap while connected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "event_bus.h"
|
||||
#include "saved_networks.h"
|
||||
#include "service.h"
|
||||
#include "services/clock_service.h"
|
||||
#include "settings.h"
|
||||
#include "wifi_controller.h"
|
||||
|
||||
namespace roro {
|
||||
|
||||
struct ScanEntry {
|
||||
std::string ssid;
|
||||
int rssi;
|
||||
bool open;
|
||||
};
|
||||
|
||||
// Owns the Wi-Fi radio: carries out the WifiController's decisions with the ESP32 Wi-Fi stack,
|
||||
// syncs the clock over NTP once Connected, and runs scans for the Settings network list.
|
||||
class WifiService : public Service {
|
||||
public:
|
||||
WifiService(Settings& settings, SavedNetworks& saved, ClockService& clock)
|
||||
: settings_(settings), saved_(saved), clock_(clock), controller_(saved) {}
|
||||
const char* name() const override { return "wifi"; }
|
||||
uint32_t tickIntervalMs() const override { return 250; }
|
||||
void tick(uint32_t nowMs) override;
|
||||
|
||||
WifiController::State state() const { return controller_.state(); }
|
||||
const std::string& ssid() const { return controller_.ssid(); }
|
||||
int rssi() const;
|
||||
|
||||
// Scan for the "add a network" list; results arrive in listScan() when listScanDone().
|
||||
void startListScan();
|
||||
bool listScanDone() const { return !listScanPending_; }
|
||||
const std::vector<ScanEntry>& listScan() const { return listScan_; }
|
||||
|
||||
// A Saved Network was added: try it now rather than after the retry delay.
|
||||
void savedNetworksChanged() { controller_.retryNow(millis()); }
|
||||
|
||||
void requestMonitor() { apply(controller_.requestMonitor()); }
|
||||
void releaseMonitor() { apply(controller_.releaseMonitor(settings_.getBool(Setting::WifiEnabled))); }
|
||||
|
||||
private:
|
||||
void apply(const WifiController::Step& step);
|
||||
void startScan();
|
||||
void finishScan(uint32_t nowMs);
|
||||
void startNtp();
|
||||
|
||||
Settings& settings_;
|
||||
SavedNetworks& saved_;
|
||||
ClockService& clock_;
|
||||
WifiController controller_;
|
||||
bool scanRunning_ = false;
|
||||
bool listScanPending_ = false;
|
||||
std::vector<ScanEntry> listScan_;
|
||||
bool ntpWaiting_ = false;
|
||||
bool radioInitialised_ = false;
|
||||
};
|
||||
|
||||
} // namespace roro
|
||||
Reference in New Issue
Block a user