mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-11-02 19:02:00 +00:00
simplify and remove 2 as a wifi enabled state
This commit is contained in:
@@ -2181,7 +2181,7 @@ 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.wifiSSID()[0] ? _prefs.wifiSSID() : "(not set)");
|
sprintf(reply, "> %s", _prefs.getWifiSSID()[0] ? _prefs.getWifiSSID() : "(not set)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (memcmp(command, "set wifi.enabled ", 17) == 0) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
if (strcmp(command, "get wifi.enabled") == 0) {
|
if (strcmp(command, "get wifi.enabled") == 0) {
|
||||||
sprintf(reply, "> %d", _prefs.wifiEnabled() ? 1 : 0);
|
sprintf(reply, "> %d", _prefs.wifi_enabled);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (strcmp(command, "get wifi.status") == 0) {
|
if (strcmp(command, "get wifi.status") == 0) {
|
||||||
|
|||||||
@@ -47,12 +47,9 @@ 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 = 2; // 0 = off, 1 = on, 2 = never set (treated as on)
|
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
|
||||||
// effective SSID: stored prefs win over the build-time one
|
const char* getWifiSSID() const { return wifi_ssid[0] ? wifi_ssid : WIFI_SSID; }
|
||||||
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:
|
||||||
|
|||||||
@@ -218,9 +218,9 @@ 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 no SSID from either prefs or the build, leaves the radio off entirely
|
// only start wifi if enabled and ssid is not empty
|
||||||
wifi_enabled = the_mesh.getNodePrefs()->wifiEnabled();
|
wifi_enabled = the_mesh.getNodePrefs()->wifi_enabled;
|
||||||
if (wifi_enabled) {
|
if (wifi_enabled && wifi_ssid[0]) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
board.setInhibitSleep(true); // prevent sleep when WiFi is active
|
board.setInhibitSleep(true); // prevent sleep when WiFi is active
|
||||||
WiFi.setAutoReconnect(true);
|
WiFi.setAutoReconnect(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user