2019-02-18 05:45:02 +00:00
|
|
|
#include "wifi.h"
|
|
|
|
|
|
|
|
void processWifiState()
|
|
|
|
{
|
2019-02-26 00:32:59 +00:00
|
|
|
switch (wifiState) {
|
2019-02-18 05:45:02 +00:00
|
|
|
case WIFI_DISCONNECTED:
|
|
|
|
commState = COMM_INIT;
|
|
|
|
|
|
|
|
if (SERIAL_LOGGING) Serial.println("[INFO] Wifi attempting to connect...");
|
|
|
|
|
|
|
|
WiFi.begin(LOCKOUT_WIFI_SSID, LOCKOUT_WIFI_PASS);
|
|
|
|
|
|
|
|
wifiState = WIFI_CONNECTING;
|
|
|
|
break;
|
|
|
|
case WIFI_CONNECTING:
|
|
|
|
commState = COMM_INIT;
|
|
|
|
|
|
|
|
if (WiFi.status() == WL_CONNECTED) {
|
|
|
|
if (SERIAL_LOGGING) Serial.println("[INFO] Wifi is connected.");
|
|
|
|
logEvent(LOG_WIFI_CONNECTED);
|
|
|
|
|
|
|
|
if (SERIAL_LOGGING) Serial.print("[INFO] Wifi IP Address: ");
|
|
|
|
if (SERIAL_LOGGING) Serial.println(WiFi.localIP());
|
|
|
|
|
|
|
|
wifiState = WIFI_CONNECTED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIFI_CONNECTED:
|
|
|
|
if (WiFi.status() != WL_CONNECTED) {
|
|
|
|
if (SERIAL_LOGGING) Serial.println("[INFO] Wifi disconnected.");
|
|
|
|
logEvent(LOG_WIFI_DISCONNECTED);
|
|
|
|
wifiState = WIFI_DISCONNECTED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (SERIAL_LOGGING) Serial.println("[ERROR] Invalid wifi state.");
|
|
|
|
wifiState = WIFI_DISCONNECTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|