simplify and remove 2 as a wifi enabled state

This commit is contained in:
liamcottle
2026-09-08 21:30:17 +12:00
parent 87a05e1589
commit 6809fed159
3 changed files with 8 additions and 11 deletions
+2 -2
View File
@@ -2181,7 +2181,7 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
return true;
}
if (strcmp(command, "get wifi.ssid") == 0) { // no 'get wifi.pwd', by design
sprintf(reply, "> %s", _prefs.wifiSSID()[0] ? _prefs.wifiSSID() : "(not set)");
sprintf(reply, "> %s", _prefs.getWifiSSID()[0] ? _prefs.getWifiSSID() : "(not set)");
return true;
}
if (memcmp(command, "set wifi.enabled ", 17) == 0) {
@@ -2191,7 +2191,7 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
return true;
}
if (strcmp(command, "get wifi.enabled") == 0) {
sprintf(reply, "> %d", _prefs.wifiEnabled() ? 1 : 0);
sprintf(reply, "> %d", _prefs.wifi_enabled);
return true;
}
if (strcmp(command, "get wifi.status") == 0) {
+3 -6
View File
@@ -47,12 +47,9 @@ public:
#ifdef WIFI_SSID
char wifi_ssid[33] = {0}; // if empty, the compile-time WIFI_SSID is used
char wifi_pwd[64] = {0};
uint8_t wifi_enabled = 2; // 0 = off, 1 = on, 2 = never set (treated as on)
// effective SSID: stored prefs win over the build-time one
const char* wifiSSID() const { return wifi_ssid[0] ? wifi_ssid : WIFI_SSID; }
// WiFi runs only when there is an SSID and it hasn't been explicitly turned off
bool wifiEnabled() const { return wifiSSID()[0] && wifi_enabled != 0; }
uint8_t wifi_enabled = 1; // enabled by default to allow wifi only builds to work. wifi won't be started if ssid is empty
// use ssid from prefs, or fallback to ssid from build flags
const char* getWifiSSID() const { return wifi_ssid[0] ? wifi_ssid : WIFI_SSID; }
#endif
private:
+3 -3
View File
@@ -218,9 +218,9 @@ void setup() {
strcpy(wifi_ssid, the_mesh.getNodePrefs()->wifi_ssid);
strcpy(wifi_pwd, the_mesh.getNodePrefs()->wifi_pwd);
}
// 'set wifi.enabled 0', or no SSID from either prefs or the build, leaves the radio off entirely
wifi_enabled = the_mesh.getNodePrefs()->wifiEnabled();
if (wifi_enabled) {
// only start wifi if enabled and ssid is not empty
wifi_enabled = the_mesh.getNodePrefs()->wifi_enabled;
if (wifi_enabled && wifi_ssid[0]) {
#if defined(ESP32)
board.setInhibitSleep(true); // prevent sleep when WiFi is active
WiFi.setAutoReconnect(true);