pslockout/firmware/wifi.cpp

41 lines
1009 B
C++

#include "wifi.h"
void processWifiState()
{
switch(wifiState) {
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;
}
}