Public Access
- 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
68 lines
2.1 KiB
C++
68 lines
2.1 KiB
C++
#include "saved_networks.h"
|
|
|
|
namespace roro {
|
|
|
|
namespace {
|
|
std::string key(int i, const char* field) { return "net" + std::to_string(i) + "_" + field; }
|
|
} // namespace
|
|
|
|
void SavedNetworks::load() {
|
|
networks_.clear();
|
|
int32_t n = 0;
|
|
store_.getInt("net_count", n);
|
|
for (int i = 0; i < n && i < kMax; i++) {
|
|
SavedNetwork net;
|
|
if (!store_.getString(key(i, "ssid").c_str(), net.ssid)) break;
|
|
store_.getString(key(i, "pass").c_str(), net.password);
|
|
int32_t hidden = 0;
|
|
store_.getInt(key(i, "hid").c_str(), hidden);
|
|
net.hidden = hidden != 0;
|
|
networks_.push_back(net);
|
|
}
|
|
}
|
|
|
|
const SavedNetwork* SavedNetworks::find(const std::string& ssid) const {
|
|
for (auto& n : networks_)
|
|
if (n.ssid == ssid) return &n;
|
|
return nullptr;
|
|
}
|
|
|
|
std::string SavedNetworks::add(const std::string& ssid, const std::string& password, bool hidden) {
|
|
if (ssid.empty() || ssid.size() > 32) return "Network name must be 1 to 32 bytes";
|
|
if (!password.empty() && (password.size() < 8 || password.size() > 63))
|
|
return "Password must be 8 to 63 characters (or empty for an open network)";
|
|
for (auto& n : networks_) {
|
|
if (n.ssid == ssid) {
|
|
n.password = password;
|
|
n.hidden = hidden;
|
|
save();
|
|
return "";
|
|
}
|
|
}
|
|
if (count() >= kMax) return "Already 8 saved networks: forget one first";
|
|
networks_.push_back({ssid, password, hidden});
|
|
save();
|
|
return "";
|
|
}
|
|
|
|
void SavedNetworks::forget(const std::string& ssid) {
|
|
for (auto it = networks_.begin(); it != networks_.end(); ++it) {
|
|
if (it->ssid == ssid) {
|
|
networks_.erase(it);
|
|
save();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SavedNetworks::save() {
|
|
for (int i = 0; i < count(); i++) {
|
|
store_.putString(key(i, "ssid").c_str(), networks_[i].ssid);
|
|
store_.putString(key(i, "pass").c_str(), networks_[i].password);
|
|
store_.putInt(key(i, "hid").c_str(), networks_[i].hidden ? 1 : 0);
|
|
}
|
|
store_.putInt("net_count", count());
|
|
}
|
|
|
|
} // namespace roro
|