Skip to content

Commit fdb2390

Browse files
committed
put back checks, sprinkle feedwdt where it needs to go
1 parent 22e357e commit fdb2390

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

src/Wippersnapper.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,36 +2362,39 @@ void Wippersnapper::runNetFSM() {
23622362
fsmNetwork = FSM_NET_ESTABLISH_NETWORK;
23632363
break;
23642364
case FSM_NET_ESTABLISH_NETWORK:
2365-
WS_DEBUG_PRINTLN("Connecting to WiFi...");
2365+
WS_DEBUG_PRINTLN("Establishing network connection...");
23662366
WS_PRINTER.flush();
23672367
#ifdef USE_DISPLAY
23682368
if (WS._ui_helper->getLoadingState())
23692369
WS._ui_helper->set_label_status("Connecting to WiFi...");
23702370
#endif
23712371
// Perform a WiFi scan and check if SSID within
23722372
// secrets.json is within the scanned SSIDs
2373-
/* if (!check_valid_ssid()) {
2373+
WS_DEBUG_PRINT("Performing a WiFi scan for SSID...");
2374+
if (!check_valid_ssid()) {
23742375
#ifdef USE_DISPLAY
23752376
WS._ui_helper->show_scr_error("ERROR",
23762377
"Unable to find WiFi network listed in "
23772378
"the secrets file. Rebooting soon...");
23782379
#endif
23792380
haltError("ERROR: Unable to find WiFi network, rebooting soon...",
23802381
WS_LED_STATUS_WIFI_CONNECTING);
2381-
} */
2382+
}
2383+
WS_DEBUG_PRINTLN("SSID found!");
23822384
// Attempt to connect to wireless network
23832385
maxAttempts = 5;
23842386
while (maxAttempts > 0) {
23852387
// blink before we connect
2386-
//statusLEDBlink(WS_LED_STATUS_WIFI_CONNECTING);
2387-
WS.feedWDT();
2388+
statusLEDBlink(WS_LED_STATUS_WIFI_CONNECTING);
2389+
feedWDT();
23882390
// attempt to connect
23892391
WS_DEBUG_PRINT("Connecting to WiFi (attempt #");
23902392
WS_DEBUG_PRINT(5-maxAttempts);
23912393
WS_DEBUG_PRINTLN(")");
23922394
WS_PRINTER.flush();
2395+
feedWDT();
23932396
_connect();
2394-
WS.feedWDT();
2397+
feedWDT();
23952398
// did we connect?
23962399
if (networkStatus() == WS_NET_CONNECTED)
23972400
break;
@@ -2428,7 +2431,8 @@ void Wippersnapper::runNetFSM() {
24282431
WS_DEBUG_PRINT("WiFi Status: ");
24292432
WS_DEBUG_PRINTLN(networkStatus());
24302433
WS_PRINTER.flush();
2431-
// statusLEDBlink(WS_LED_STATUS_MQTT_CONNECTING);
2434+
feedWDT();
2435+
statusLEDBlink(WS_LED_STATUS_MQTT_CONNECTING);
24322436
feedWDT();
24332437
int8_t mqttRC = WS._mqtt->connect();
24342438
feedWDT();
@@ -2438,7 +2442,7 @@ void Wippersnapper::runNetFSM() {
24382442
}
24392443
WS_DEBUG_PRINTLN(
24402444
"Unable to connect to Adafruit IO MQTT, retrying in 3 seconds...");
2441-
//statusLEDBlink(WS_LED_STATUS_MQTT_CONNECTING);
2445+
statusLEDBlink(WS_LED_STATUS_MQTT_CONNECTING);
24422446
maxAttempts--;
24432447
}
24442448
if (fsmNetwork != FSM_NET_CHECK_MQTT) {

src/Wippersnapper.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@
105105
{} ///< Prints line from debug output.
106106
#endif
107107

108-
#ifdef ARDUINO_ARCH_RP2040
109-
#define delay(ms) delayMicroseconds(ms * 1000); // Use non-blocking delay() call for RP2040 architectures
110-
#endif
111-
112108
/** Defines the Adafruit IO connection status */
113109
typedef enum {
114110
WS_IDLE = 0, // Waiting for connection establishement

src/network_interfaces/ws_networking_pico.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class ws_networking_pico : public Wippersnapper {
9797
// connected
9898
WiFi.mode(WIFI_STA);
9999
WiFi.disconnect();
100-
delayMicroseconds(100000);
100+
delay(100);
101101

102102
// Perform a network scan
103103
int n = WiFi.scanNetworks();
@@ -261,21 +261,22 @@ class ws_networking_pico : public Wippersnapper {
261261
_status = WS_SSID_INVALID;
262262
} else {
263263
_disconnect();
264-
WS.feedWDT();
265-
delayMicroseconds(5000000);
264+
delay(5000);
266265
WS.feedWDT();
267266
WiFi.mode(WIFI_STA);
268267
WS.feedWDT();
269268
WiFi.setTimeout(20000);
270269
WS.feedWDT();
271270
WiFi.begin(_ssid, _pass);
271+
// Here, we're going to wait 20 seconds total, matching the value within
272+
// setTimeout().
273+
// However, due to the global WDT of 6 sec., we need to feed the WDT
274+
// after every 5 seconds.
272275
for (int i = 0; i < 4; i++) {
273-
// WS_DEBUG_PRINTLN("Delaying 5 seconds...");
274-
delayMicroseconds(5000000);
276+
delay(5000);
275277
WS.feedWDT();
276278
}
277279
_status = WS_NET_DISCONNECTED;
278-
279280
}
280281
}
281282

@@ -285,8 +286,10 @@ class ws_networking_pico : public Wippersnapper {
285286
*/
286287
/**************************************************************************/
287288
void _disconnect() {
289+
WS.feedWDT();
288290
WiFi.disconnect();
289-
delayMicroseconds(500000);
291+
delay(5000);
292+
WS.feedWDT();
290293
}
291294
};
292295

0 commit comments

Comments
 (0)