Remember and use last known mac address for immediate display
This commit is contained in:
@@ -248,6 +248,7 @@ bool JsonSettingsIO::loadKOReader(KOReaderCredentialStore& store, const char* js
|
|||||||
bool JsonSettingsIO::saveWifi(const WifiCredentialStore& store, const char* path) {
|
bool JsonSettingsIO::saveWifi(const WifiCredentialStore& store, const char* path) {
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
doc["lastConnectedSsid"] = store.getLastConnectedSsid();
|
doc["lastConnectedSsid"] = store.getLastConnectedSsid();
|
||||||
|
doc["lastKnownMacAddress"] = store.getLastKnownMacAddress();
|
||||||
|
|
||||||
JsonArray arr = doc["credentials"].to<JsonArray>();
|
JsonArray arr = doc["credentials"].to<JsonArray>();
|
||||||
for (const auto& cred : store.getCredentials()) {
|
for (const auto& cred : store.getCredentials()) {
|
||||||
@@ -271,6 +272,7 @@ bool JsonSettingsIO::loadWifi(WifiCredentialStore& store, const char* json, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
store.lastConnectedSsid = doc["lastConnectedSsid"] | std::string("");
|
store.lastConnectedSsid = doc["lastConnectedSsid"] | std::string("");
|
||||||
|
store.lastKnownMacAddress = doc["lastKnownMacAddress"] | std::string("");
|
||||||
|
|
||||||
store.credentials.clear();
|
store.credentials.clear();
|
||||||
JsonArray arr = doc["credentials"].as<JsonArray>();
|
JsonArray arr = doc["credentials"].as<JsonArray>();
|
||||||
|
|||||||
@@ -168,9 +168,19 @@ void WifiCredentialStore::clearLastConnectedSsid() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WifiCredentialStore::setLastKnownMacAddress(const std::string& mac) {
|
||||||
|
if (lastKnownMacAddress != mac) {
|
||||||
|
lastKnownMacAddress = mac;
|
||||||
|
saveToFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& WifiCredentialStore::getLastKnownMacAddress() const { return lastKnownMacAddress; }
|
||||||
|
|
||||||
void WifiCredentialStore::clearAll() {
|
void WifiCredentialStore::clearAll() {
|
||||||
credentials.clear();
|
credentials.clear();
|
||||||
lastConnectedSsid.clear();
|
lastConnectedSsid.clear();
|
||||||
|
lastKnownMacAddress.clear();
|
||||||
saveToFile();
|
saveToFile();
|
||||||
LOG_DBG("WCS", "Cleared all WiFi credentials");
|
LOG_DBG("WCS", "Cleared all WiFi credentials");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class WifiCredentialStore {
|
|||||||
static WifiCredentialStore instance;
|
static WifiCredentialStore instance;
|
||||||
std::vector<WifiCredential> credentials;
|
std::vector<WifiCredential> credentials;
|
||||||
std::string lastConnectedSsid;
|
std::string lastConnectedSsid;
|
||||||
|
std::string lastKnownMacAddress;
|
||||||
|
|
||||||
static constexpr size_t MAX_NETWORKS = 8;
|
static constexpr size_t MAX_NETWORKS = 8;
|
||||||
|
|
||||||
@@ -63,6 +64,10 @@ class WifiCredentialStore {
|
|||||||
const std::string& getLastConnectedSsid() const;
|
const std::string& getLastConnectedSsid() const;
|
||||||
void clearLastConnectedSsid();
|
void clearLastConnectedSsid();
|
||||||
|
|
||||||
|
// Last known device MAC (formatted as AA-BB-CC-DD-EE-FF for instant UI display)
|
||||||
|
void setLastKnownMacAddress(const std::string& mac);
|
||||||
|
const std::string& getLastKnownMacAddress() const;
|
||||||
|
|
||||||
// Clear all credentials
|
// Clear all credentials
|
||||||
void clearAll();
|
void clearAll();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,6 +13,27 @@
|
|||||||
#include "components/UITheme.h"
|
#include "components/UITheme.h"
|
||||||
#include "fontIds.h"
|
#include "fontIds.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
bool isLikelyValidMac(const uint8_t mac[6]) {
|
||||||
|
bool allZero = true;
|
||||||
|
bool allFF = true;
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
allZero = allZero && (mac[i] == 0x00);
|
||||||
|
allFF = allFF && (mac[i] == 0xFF);
|
||||||
|
}
|
||||||
|
return !allZero && !allFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string formatMacLabel(const uint8_t mac[6]) {
|
||||||
|
char macStr[64];
|
||||||
|
snprintf(macStr, sizeof(macStr), "%s %02x-%02x-%02x-%02x-%02x-%02x", tr(STR_MAC_ADDRESS), mac[0], mac[1], mac[2],
|
||||||
|
mac[3], mac[4], mac[5]);
|
||||||
|
return std::string(macStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void WifiSelectionActivity::onEnter() {
|
void WifiSelectionActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
|
|
||||||
@@ -23,6 +44,13 @@ void WifiSelectionActivity::onEnter() {
|
|||||||
WIFI_STORE.loadFromFile();
|
WIFI_STORE.loadFromFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show persisted MAC immediately so UI doesn't briefly display a bogus value.
|
||||||
|
if (!WIFI_STORE.getLastKnownMacAddress().empty()) {
|
||||||
|
cachedMacAddress = std::string(tr(STR_MAC_ADDRESS)) + " " + WIFI_STORE.getLastKnownMacAddress();
|
||||||
|
} else {
|
||||||
|
cachedMacAddress = std::string(tr(STR_MAC_ADDRESS)) + " --";
|
||||||
|
}
|
||||||
|
|
||||||
// Reset state
|
// Reset state
|
||||||
selectedNetworkIndex = 0;
|
selectedNetworkIndex = 0;
|
||||||
networks.clear();
|
networks.clear();
|
||||||
@@ -36,13 +64,19 @@ void WifiSelectionActivity::onEnter() {
|
|||||||
forgetPromptSelection = 0;
|
forgetPromptSelection = 0;
|
||||||
autoConnecting = false;
|
autoConnecting = false;
|
||||||
|
|
||||||
// Cache MAC address for display
|
// Refresh displayed MAC from live hardware value when valid.
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
char macStr[64];
|
if (isLikelyValidMac(mac)) {
|
||||||
snprintf(macStr, sizeof(macStr), "%s %02x-%02x-%02x-%02x-%02x-%02x", tr(STR_MAC_ADDRESS), mac[0], mac[1], mac[2],
|
cachedMacAddress = formatMacLabel(mac);
|
||||||
mac[3], mac[4], mac[5]);
|
char persistedMac[18];
|
||||||
cachedMacAddress = std::string(macStr);
|
snprintf(persistedMac, sizeof(persistedMac), "%02x-%02x-%02x-%02x-%02x-%02x", mac[0], mac[1], mac[2], mac[3],
|
||||||
|
mac[4], mac[5]);
|
||||||
|
if (WIFI_STORE.getLastKnownMacAddress() != persistedMac) {
|
||||||
|
RenderLock lock(*this);
|
||||||
|
WIFI_STORE.setLastKnownMacAddress(persistedMac);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger first update to show scanning message
|
// Trigger first update to show scanning message
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
|
|||||||
Reference in New Issue
Block a user