Skip to content

Commit

Permalink
Add logging of WiFi settings at boot
Browse files Browse the repository at this point in the history
  • Loading branch information
laszloh committed Feb 4, 2024
1 parent 4cec33b commit 7d6c9f6
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Wlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ static void migrateFromVersion2() {
};

if (gPrefsSettings.isKey(nvsKey)) {
iterateNvsEntries([](const char *key, const WiFiSettings &) {
prefsWifiSettings.remove(key);
return true;
});

const size_t numNetworks = gPrefsSettings.getBytesLength(nvsKey) / sizeof(OldWiFiSettings);
OldWiFiSettings *settings = new OldWiFiSettings[numNetworks];
gPrefsSettings.getBytes(nvsKey, settings, numNetworks * sizeof(OldWiFiSettings));
Expand Down Expand Up @@ -247,6 +242,21 @@ void Wlan_Init(void) {
return;
}

// dump all network settings
iterateNvsEntries([](const char *, const WiFiSettings &s) {
char buffer[128]; // maximum buffer needed when we have static IP
const char *ipMode = "dynamic IP";

if (s.staticIp.isValid()) {
snprintf(buffer, sizeof(buffer), "ip: %s, subnet: %s, gateway: %s, dns1: %s, dns2: %s", s.staticIp.addr.toString().c_str(),
s.staticIp.subnet.toString().c_str(), s.staticIp.gateway.toString().c_str(), s.staticIp.dns1.toString().c_str(),
s.staticIp.dns2.toString().c_str());
ipMode = buffer;
}
Log_Printf(LOGLEVEL_DEBUG, "SSID: %s, Password: %s, %s", s.ssid.c_str(), (s.password.length()) ? "yes" : "no", ipMode);
return true;
});

// The use of dynamic allocation is recommended to save memory and reduce resources usage.
// However, the dynamic performs slightly slower than the static allocation.
// Use static allocation if you want to have more performance and if your application is multi-tasking.
Expand Down Expand Up @@ -611,8 +621,7 @@ bool Wlan_AddNetworkSettings(const WiFiSettings &settings) {
if (nvsSetting) {
// we are updating an existing entry
Log_Printf(LOGLEVEL_NOTICE, wifiUpdateNetwork, settings.ssid);
storeWiFiSettingsToNvs(nvsSetting->key, settings);
return true;
return storeWiFiSettingsToNvs(nvsSetting->key, settings);
}

// this is a new entry, find the first unused key
Expand All @@ -622,8 +631,7 @@ bool Wlan_AddNetworkSettings(const WiFiSettings &settings) {
if (!prefsWifiSettings.isKey(key)) {
// we found a slot, use it
Log_Printf(LOGLEVEL_NOTICE, wifiAddNetwork, settings.ssid);
storeWiFiSettingsToNvs(key, settings);
return true;
return storeWiFiSettingsToNvs(key, settings);
}
}

Expand Down

0 comments on commit 7d6c9f6

Please sign in to comment.