S1 #7 step 3: the Wi-Fi Service applies IP, DNS and NTP settings

Joining a Saved Network uses its Fixed address, mask and gateway, or
DHCP. DNS comes from Settings on Fixed networks and when "Always use my
DNS" is on; NTP servers come from Settings, after any that DHCP offered.
Both are re-checked every 30 s, since a DHCP renewal puts DHCP's DNS back
and clears the NTP slots it didn't fill. `wifi status` shows what's in
use, where it came from, and which NTP servers answered; `wifi ip`,
`wifi dns`, `wifi ntp`. Debug Builds: `wifi ip ... try <s>` reverts
unless kept.

On knbg-guests (10.39.39.0/24, gateway .1): Fixed .12 and .13 both reach
the internet through 9.9.9.9; a wrong gateway on trial cut the device off
and came back by itself; back to DHCP; both NTP servers answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-05 23:52:22 +02:00
co-authored by Claude Opus 5.5
parent bdd027cb50
commit 3e279738b6
3 changed files with 239 additions and 9 deletions
+28
View File
@@ -36,6 +36,27 @@ class WifiService : public Service {
// Done with list scans: switch the radio back off if Wi-Fi itself is off.
void endListScans();
// What the device is using and where each part came from (S1, Q113).
struct Connection {
bool connected = false;
bool fixed = false; // the address: Fixed, or from DHCP
bool dnsFromSettings = false; // DNS: from Settings, or from DHCP
std::string address, mask, gateway;
int prefix = 0;
std::string dns[2];
struct Ntp {
std::string server;
bool fromDhcp = false;
bool answered = false; // it has replied since the last (re)start
} ntp[3];
int ntpCount = 0;
};
Connection connection() const;
// A Saved Network's IP setting changed: if it's the one in use, join it again with it (Q114).
void ipSettingChanged(const std::string& ssid);
// The DNS or NTP settings changed: use them now.
void serversChanged() { applyServers(Why::SettingsChanged); }
// A Saved Network was added: try it now rather than after the retry delay.
void savedNetworksChanged() { controller_.retryNow(millis()); }
@@ -47,6 +68,9 @@ class WifiService : public Service {
void startScan(int channel = 0);
void finishScan(uint32_t nowMs);
void startNtp();
void join(const std::string& ssid, const std::string& password);
enum class Why { Joined, SettingsChanged, Check };
void applyServers(Why why); // DNS and NTP, as Settings and the network say
Settings& settings_;
SavedNetworks& saved_;
@@ -58,6 +82,10 @@ class WifiService : public Service {
uint32_t listScanSeq_ = 0;
bool ntpWaiting_ = false;
bool radioInitialised_ = false;
bool fixed_ = false; // the network in use has a Fixed address
bool dnsFromSettings_ = false;
std::string ntpNames_[2]; // lwIP keeps the pointers, so the names live here
uint32_t serversCheckedMs_ = 0;
};
} // namespace roro