Skip to content

Instantly share code, notes, and snippets.

@St3venAU
Last active May 24, 2017 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save St3venAU/8367e1e8b0a267ae558326aaf9888c94 to your computer and use it in GitHub Desktop.
Save St3venAU/8367e1e8b0a267ae558326aaf9888c94 to your computer and use it in GitHub Desktop.
#include <WiFi.h>
const char* ssid = "*****"; // Removed for privacy
const char* password = "*****"; // Removed for privacy
uint8_t n = 0;
void setup() {
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.mode(WIFI_STA);
WiFi.setAutoReconnect(true);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected");
}
void loop() {
delay(100);
if (++n == 100) { // Every 10 seconds
n = 0;
Serial.println(getWifiStatus());
//if (WiFi.status() != WL_CONNECTED) {
// Serial.println("Attempting to reconnect");
// WiFi.reconnect();
//}
}
}
String getWifiStatus() {
switch (WiFi.status()) {
case 0:
return String("IDLE_STATUS");
case 1:
return String("NO_SSID_AVAIL");
case 2:
return String("SCAN_COMPLETED");
case 3:
return String("CONNECTED");
case 4:
return String("CONNECT_FAILED");
case 5:
return String("CONNECTION_LOST");
case 6:
return String("DISCONNECTED");
case 255:
return String("NO_SHIELD");
}
return String("UNKNOWN");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment