Skip to content

Commit ec03482

Browse files
committed
Add wifiPrintState
1 parent 7b96708 commit ec03482

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ bool wifiConnect(unsigned long timeout, bool useAPSTAMode, bool *wasInAPmode)
233233
if (wifiStatus == WL_DISCONNECTED)
234234
systemPrint("No friendly WiFi networks detected.\r\n");
235235
else
236-
systemPrintf("WiFi failed to connect: error #%d.\r\n", wifiStatus);
236+
{
237+
systemPrintf("WiFi failed to connect: error #%d - %s\r\n", wifiStatus, wifiPrintState((wl_status_t)wifiStatus));
238+
}
237239
wifiRunning = false;
238240
return false;
239241
}
@@ -255,37 +257,8 @@ void wifiDisplayState()
255257

256258
// Get the WiFi status
257259
wl_status_t wifiStatus = WiFi.status();
258-
const char *wifiStatusString;
259-
switch (wifiStatus)
260-
{
261-
case WL_NO_SHIELD:
262-
wifiStatusString = "WL_NO_SHIELD";
263-
break;
264-
case WL_STOPPED:
265-
wifiStatusString = "WL_STOPPED";
266-
break;
267-
case WL_IDLE_STATUS:
268-
wifiStatusString = "WL_IDLE_STATUS";
269-
break;
270-
case WL_NO_SSID_AVAIL:
271-
wifiStatusString = "WL_NO_SSID_AVAIL";
272-
break;
273-
case WL_SCAN_COMPLETED:
274-
wifiStatusString = "WL_SCAN_COMPLETED";
275-
break;
276-
case WL_CONNECTED:
277-
wifiStatusString = "WL_CONNECTED";
278-
break;
279-
case WL_CONNECT_FAILED:
280-
wifiStatusString = "WL_CONNECT_FAILED";
281-
break;
282-
case WL_CONNECTION_LOST:
283-
wifiStatusString = "WL_CONNECTION_LOST";
284-
break;
285-
case WL_DISCONNECTED:
286-
wifiStatusString = "WL_DISCONNECTED";
287-
break;
288-
}
260+
261+
const char *wifiStatusString = wifiPrintState(wifiStatus);
289262

290263
// Display the WiFi state
291264
systemPrintf(" SSID: %s\r\n", WiFi.STA.SSID());
@@ -429,6 +402,35 @@ int wifiNetworkCount()
429402
return networkCount;
430403
}
431404

405+
//----------------------------------------
406+
// Given a status, return the associated state or error
407+
//----------------------------------------
408+
const char *wifiPrintState(wl_status_t wifiStatus)
409+
{
410+
switch (wifiStatus)
411+
{
412+
case WL_NO_SHIELD:
413+
return ("WL_NO_SHIELD"); // 255
414+
case WL_STOPPED:
415+
return ("WL_STOPPED");
416+
case WL_IDLE_STATUS: // 0
417+
return ("WL_IDLE_STATUS");
418+
case WL_NO_SSID_AVAIL: // 1
419+
return ("WL_NO_SSID_AVAIL");
420+
case WL_SCAN_COMPLETED: // 2
421+
return ("WL_SCAN_COMPLETED");
422+
case WL_CONNECTED: // 3
423+
return ("WL_CONNECTED");
424+
case WL_CONNECT_FAILED: // 4
425+
return ("WL_CONNECT_FAILED");
426+
case WL_CONNECTION_LOST: // 5
427+
return ("WL_CONNECTION_LOST");
428+
case WL_DISCONNECTED: // 6
429+
return ("WL_DISCONNECTED");
430+
}
431+
return ("WiFi Status Unknown");
432+
}
433+
432434
//----------------------------------------
433435
// Restart WiFi
434436
//----------------------------------------

0 commit comments

Comments
 (0)