Skip to content

Commit d0bb5c5

Browse files
committed
Define magic numbers for timeout/retry + print SSID in multi mode
1 parent 0d959cd commit d0bb5c5

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/network_interfaces/Wippersnapper_ESP32.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,20 @@ class Wippersnapper_ESP32 : public Wippersnapper {
111111
// Was the network within secrets.json found?
112112
for (int i = 0; i < n; ++i) {
113113
if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0) {
114-
WS_DEBUG_PRINT("SSID found! RSSI: ");
114+
WS_DEBUG_PRINT("SSID (");
115+
WS_DEBUG_PRINT(_ssid);
116+
WS_DEBUG_PRINT(") found! RSSI: ");
115117
WS_DEBUG_PRINTLN(WiFi.RSSI(i));
116118
return true;
117119
}
118120
if (WS._isWiFiMulti) {
119121
// multi network mode
120122
for (int j = 0; j < WS_MAX_ALT_WIFI_NETWORKS; j++) {
121123
if (strcmp(WS._multiNetworks[j].ssid, WiFi.SSID(i).c_str()) == 0) {
124+
WS_DEBUG_PRINT("SSID (");
125+
WS_DEBUG_PRINT(WS._multiNetworks[j].ssid);
126+
WS_DEBUG_PRINT(") found! RSSI: ");
127+
WS_DEBUG_PRINTLN(WiFi.RSSI(i));
122128
return true;
123129
}
124130
}

src/network_interfaces/Wippersnapper_ESP8266.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,22 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
136136
// Was the network within secrets.json found?
137137
for (int i = 0; i < n; ++i) {
138138
if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0) {
139-
WS_DEBUG_PRINT("SSID found! RSSI: ");
139+
WS_DEBUG_PRINT("SSID (");
140+
WS_DEBUG_PRINT(_ssid);
141+
WS_DEBUG_PRINT(") found! RSSI: ");
140142
WS_DEBUG_PRINTLN(WiFi.RSSI(i));
141143
return true;
142144
}
143145
if (WS._isWiFiMulti) {
144146
// multi network mode
145147
for (int j = 0; j < WS_MAX_ALT_WIFI_NETWORKS; j++) {
146-
if (strcmp(WS._multiNetworks[j].ssid, WiFi.SSID(i).c_str()) == 0)
148+
if (strcmp(WS._multiNetworks[j].ssid, WiFi.SSID(i).c_str()) == 0) {
149+
WS_DEBUG_PRINT("SSID (");
150+
WS_DEBUG_PRINT(WS._multiNetworks[j].ssid);
151+
WS_DEBUG_PRINT(") found! RSSI: ");
152+
WS_DEBUG_PRINTLN(WiFi.RSSI(i));
147153
return true;
154+
}
148155
}
149156
}
150157
}
@@ -257,7 +264,7 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
257264
_status = WS_NET_DISCONNECTED;
258265
delay(100);
259266

260-
if (strlen(WS._multiNetworks[0].ssid) > 0) {
267+
if (WS._isWiFiMulti) {
261268
// multi network mode
262269
for (int i = 0; i < WS_MAX_ALT_WIFI_NETWORKS; i++) {
263270
if (strlen(WS._multiNetworks[i].ssid) > 0 &&

src/network_interfaces/ws_networking_pico.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#define WS_NETWORKING_PICO_H
1919

2020
#ifdef ARDUINO_ARCH_RP2040
21+
22+
#define PICO_CONNECT_TIMEOUT_MS 20000 /*!< Connection timeout (in ms) */
23+
#define PICO_CONNECT_RETRY_DELAY_MS 200 /*!< delay time between retries. */
24+
2125
#include "Wippersnapper.h"
2226

2327
#include "Adafruit_MQTT.h"
@@ -108,15 +112,21 @@ class ws_networking_pico : public Wippersnapper {
108112

109113
// Was the network within secrets.json found?
110114
for (int i = 0; i < n; ++i) {
111-
if (strcmp(_ssid, WiFi.SSID(i)) == 0) {
112-
WS_DEBUG_PRINT("SSID found! RSSI: ");
115+
if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0) {
116+
WS_DEBUG_PRINT("SSID (");
117+
WS_DEBUG_PRINT(_ssid);
118+
WS_DEBUG_PRINT(") found! RSSI: ");
113119
WS_DEBUG_PRINTLN(WiFi.RSSI(i));
114120
return true;
115121
}
116122
if (WS._isWiFiMulti) {
117123
// multi network mode
118124
for (int j = 0; j < WS_MAX_ALT_WIFI_NETWORKS; j++) {
119-
if (strcmp(WS._multiNetworks[j].ssid, WiFi.SSID(i)) == 0) {
125+
if (strcmp(WS._multiNetworks[j].ssid, WiFi.SSID(i).c_str()) == 0) {
126+
WS_DEBUG_PRINT("SSID (");
127+
WS_DEBUG_PRINT(WS._multiNetworks[j].ssid);
128+
WS_DEBUG_PRINT(") found! RSSI: ");
129+
WS_DEBUG_PRINTLN(WiFi.RSSI(i));
120130
return true;
121131
}
122132
}
@@ -309,16 +319,16 @@ class ws_networking_pico : public Wippersnapper {
309319
WS.feedWDT();
310320
} else {
311321
WiFi.begin(_ssid, _pass);
312-
322+
313323
// Use the macro to retry the status check until connected / timed out
314324
int lastResult;
315325
RETRY_FUNCTION_UNTIL_TIMEOUT(
316326
[]() -> int { return WiFi.status(); }, // Function call each cycle
317327
int, // return type
318328
lastResult, // return variable (unused here)
319329
[](int status) { return status == WL_CONNECTED; }, // check
320-
20000, // timeout interval (ms)
321-
200); // interval between retries
330+
PICO_CONNECT_TIMEOUT_MS, // timeout interval (ms)
331+
PICO_CONNECT_RETRY_DELAY_MS); // interval between retries
322332

323333
if (lastResult == WL_CONNECTED) {
324334
_status = WS_NET_CONNECTED;

0 commit comments

Comments
 (0)