setup()
{
WiFi.begin( rssiSSID , password );
int WLcount = 0;
while (WiFi.status() != WL_CONNECTED && WLcount < 250 )
{
delay( 100 );
#ifdef DEBUG
Serial.print(".");
#endif
++WLcount;
}
}
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
// PUT_YOUR_UP_TIME_CODE_HERE
#ifdef DEBUG
Serial.print("C");
if (UpCount >= 20) // just keep terminal from scrolling sideways
{
UpCount = 0;
Serial.println();
}
++UpCount;
#endif
// END WiFi connected loop()
} else
{
// PUT_YOUR_DOWN_TIME_CODE_HERE
// WiFi DOWN loop
#ifdef DEBUG
WFstatus = getWifiStatus( WFstatus );
#endif
WiFi.begin( rssiSSID , password );
int WLcount = 0;
// loop - depending on router, connect can be from 4 - 20 seconds
// usually longer to reconnect than the connect at boot
// lopping till reconnect seems to let it settle
// usually around 80 count to breakout
while (WiFi.status() != WL_CONNECTED && WLcount < 250 )
{
delay( 100 );
#ifdef DEBUG
Serial.print(".");
// just keep terminal from scrolling sideways in test
if (UpCount >= 20)
{
UpCount = 0;
Serial.println();
}
++UpCount;
#endif
++WLcount;
}
delay( 1000 );
} // END WiFi DOWN
} // END loop()
int getWifiStatus( int WiFiStatus )
{
WiFiStatus = WiFi.status();
Serial.print("\tStatus "); Serial.print( WiFiStatus );
switch( WiFiStatus )
{
case WL_IDLE_STATUS : // WL_IDLE_STATUS = 0,
Serial.println(", WiFi IDLE ");
break;
case WL_NO_SSID_AVAIL: // WL_NO_SSID_AVAIL = 1,
Serial.println(", NO SSID AVAIL ");
break;
case WL_SCAN_COMPLETED: // WL_SCAN_COMPLETED = 2,
Serial.println(", WiFi SCAN_COMPLETED ");
break;
case WL_CONNECTED: // WL_CONNECTED = 3,
Serial.println(", WiFi CONNECTED ");
WiFi.persistent(true);
break;
case WL_CONNECT_FAILED: // WL_CONNECT_FAILED = 4,
Serial.println(", WiFi WL_CONNECT FAILED");
break;
case WL_CONNECTION_LOST: // WL_CONNECTION_LOST = 5,
Serial.println(", WiFi CONNECTION LOST");
WiFi.persistent(false); // don't keep writing FLASH
break;
case WL_DISCONNECTED: // WL_DISCONNECTED = 6
Serial.println(", WiFi DISCONNECTED ==");
break;
}
return WiFiStatus;
} // END getWifiStatus()