WiFi on/off tri-state: on when SSID set unless explicitly disabled; PicoW ships no default SSID

This commit is contained in:
Michael Graff
2026-09-06 22:18:00 -05:00
parent dac171b49c
commit 7c2b4d88be
4 changed files with 21 additions and 11 deletions
+9 -4
View File
@@ -2184,17 +2184,22 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
return true; return true;
} }
if (strcmp(command, "get wifi.ssid") == 0) { // no 'get wifi.pwd', by design if (strcmp(command, "get wifi.ssid") == 0) { // no 'get wifi.pwd', by design
sprintf(reply, "> %s", _prefs.wifi_ssid[0] ? _prefs.wifi_ssid : WIFI_SSID); sprintf(reply, "> %s", _prefs.wifiSSID()[0] ? _prefs.wifiSSID() : "(not set)");
return true; return true;
} }
if (memcmp(command, "set wifi.enabled ", 17) == 0) { if (memcmp(command, "set wifi.enabled ", 17) == 0) {
_prefs.wifi_enabled = atoi(&command[17]) ? 1 : 0; uint8_t en = atoi(&command[17]) ? 1 : 0;
if (en && !_prefs.wifiSSID()[0]) {
strcpy(reply, "> set wifi.ssid first");
return true;
}
_prefs.wifi_enabled = en;
savePrefs(); savePrefs();
sprintf(reply, "> wifi.enabled is now %d (reboot to apply)", _prefs.wifi_enabled); sprintf(reply, "> wifi.enabled is now %d (reboot to apply)", en);
return true; return true;
} }
if (strcmp(command, "get wifi.enabled") == 0) { if (strcmp(command, "get wifi.enabled") == 0) {
sprintf(reply, "> %d", _prefs.wifi_enabled); sprintf(reply, "> %d", _prefs.wifiEnabled() ? 1 : 0);
return true; return true;
} }
if (strcmp(command, "get wifi.status") == 0) { if (strcmp(command, "get wifi.status") == 0) {
+6 -1
View File
@@ -47,7 +47,12 @@ public:
#ifdef WIFI_SSID #ifdef WIFI_SSID
char wifi_ssid[33] = {0}; // if empty, the compile-time WIFI_SSID is used char wifi_ssid[33] = {0}; // if empty, the compile-time WIFI_SSID is used
char wifi_pwd[64] = {0}; char wifi_pwd[64] = {0};
uint8_t wifi_enabled = 0; // off until 'set wifi.enabled 1' (credentials may still be baked in) 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; }
#endif #endif
private: private:
+2 -2
View File
@@ -218,8 +218,8 @@ void setup() {
strcpy(wifi_ssid, the_mesh.getNodePrefs()->wifi_ssid); strcpy(wifi_ssid, the_mesh.getNodePrefs()->wifi_ssid);
strcpy(wifi_pwd, the_mesh.getNodePrefs()->wifi_pwd); strcpy(wifi_pwd, the_mesh.getNodePrefs()->wifi_pwd);
} }
// 'set wifi.enabled 0' or a build with blank credentials leaves the radio off entirely // 'set wifi.enabled 0', or no SSID from either prefs or the build, leaves the radio off entirely
wifi_enabled = the_mesh.getNodePrefs()->wifi_enabled && wifi_ssid[0]; wifi_enabled = the_mesh.getNodePrefs()->wifiEnabled();
if (wifi_enabled) { if (wifi_enabled) {
#if defined(ESP32) #if defined(ESP32)
board.setInhibitSleep(true); // prevent sleep when WiFi is active board.setInhibitSleep(true); // prevent sleep when WiFi is active
+4 -4
View File
@@ -94,8 +94,8 @@ build_flags = ${rpi_picow.build_flags}
-D BLE_PIN_CODE=123456 -D BLE_PIN_CODE=123456
; NOTE: DO NOT ENABLE --> -D BLE_DEBUG_LOGGING=1 (shares Serial with the USB interface) ; NOTE: DO NOT ENABLE --> -D BLE_DEBUG_LOGGING=1 (shares Serial with the USB interface)
; NOTE: DO NOT ENABLE --> -D WIFI_DEBUG_LOGGING=1 ; NOTE: DO NOT ENABLE --> -D WIFI_DEBUG_LOGGING=1
-D WIFI_SSID='"myssid"' -D WIFI_SSID='""' ; no default network, configure with 'set wifi.ssid' / 'set wifi.pwd'
-D WIFI_PWD='"mypwd"' -D WIFI_PWD='""'
; -D MESH_PACKET_LOGGING=1 ; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1 ; -D MESH_DEBUG=1
build_src_filter = ${rpi_picow.build_src_filter} build_src_filter = ${rpi_picow.build_src_filter}
@@ -111,8 +111,8 @@ build_flags = ${rpi_picow.build_flags}
-D MAX_CONTACTS=100 -D MAX_CONTACTS=100
-D MAX_GROUP_CHANNELS=8 -D MAX_GROUP_CHANNELS=8
-D WIFI_DEBUG_LOGGING=1 -D WIFI_DEBUG_LOGGING=1
-D WIFI_SSID='"myssid"' -D WIFI_SSID='""' ; no default network, configure with 'set wifi.ssid' / 'set wifi.pwd'
-D WIFI_PWD='"mypwd"' -D WIFI_PWD='""'
; -D MESH_PACKET_LOGGING=1 ; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1 ; -D MESH_DEBUG=1
build_src_filter = ${rpi_picow.build_src_filter} build_src_filter = ${rpi_picow.build_src_filter}