Files
roro9stack/lib/wifi/src/saved_networks.h
T
twislaandClaude Opus 5.5 1a0baf4ac7 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
2026-10-02 14:46:07 +02:00

40 lines
1.1 KiB
C++

#pragma once
#include <string>
#include <vector>
#include "key_value_store.h"
namespace roro {
struct SavedNetwork {
std::string ssid;
std::string password; // empty for an open network
bool hidden = false; // doesn't broadcast its name, so never shows up in scans
};
// The Saved Networks the Wi-Fi Service may join (see CONTEXT.md), persisted in internal flash.
class SavedNetworks {
public:
static constexpr int kMax = 8;
explicit SavedNetworks(KeyValueStore& store) : store_(store) {}
void load();
int count() const { return static_cast<int>(networks_.size()); }
const SavedNetwork& at(int i) const { return networks_[i]; }
const SavedNetwork* find(const std::string& ssid) const;
// Adds, or updates the password of an existing SSID. Empty on success, otherwise why not.
std::string add(const std::string& ssid, const std::string& password, bool hidden = false);
void forget(const std::string& ssid);
private:
void save();
KeyValueStore& store_;
std::vector<SavedNetwork> networks_;
};
} // namespace roro