I need to check if connection to WIFI has been lost so I decided to check the number of connected clients.
I found this topic: viewtopic.php?f=6&t=8402 and registering a callback seems to be the best option. I have a problem though - I am not sure how to do it. I'm using Arduino IDE to program the board ESP8266 12E.
My includes:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>I tried something like this:
void wifi_handle_event_cb(System_Event_t *evt){
switch (evt->event){
case EVENT_STAMODE_CONNECTED:
//there is new connection
break;
case EVENT_STAMODE_DISCONNECTED:
//connection has been lost
break;
default:
break;
}
}
void setup() {
delay(1000);
Serial.begin(9600);
wifi_set_event_handler_cb(wifi_handle_event_cb);
WiFi.softAP(ssid, password);
IPAddress apip = WiFi.softAPIP();
server.begin();
}
I get the following errors:
error: variable or field 'wifi_handle_event_cb' declared void
error: 'System_Event_t' was not declared in this scope
error: 'evt' was not declared in this scope
It looks like I am missing some includes, I tried adding different ones though and it didn't help.