It uses the ESP8266WiFi library.
Until there is a disconnect it works fine; however I cant see how to get it to reconnect.
Full project is described here
http://www.skillbank.co.uk/arduino/pinglogger.htm
and the relevant bits of the sketch -
#include <ESP8266WiFi.h> //WiFi functions
...
WiFiEventHandler gotIpEventHandler, disconnectedEventHandler;
...
and in setup()
//monitor Wifi connection and handle D0
gotIpEventHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP & event)
{
Serial.print("Station connected, IP: ");
Serial.println(WiFi.localIP());
digitalWrite(dPin[1], 0); //blue LED
});
disconnectedEventHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected & event)
{
Serial.println("Station disconnected");
digitalWrite(dPin[1], 1); //blue LED
});
bool stationConnected = WiFi.begin(ssid, pass);
delay(200); //allow time to connect
// Wait until connection completed
Serial.print("Connecting to AP...");
while (WiFi.status() != WL_CONNECTED) {
delay(200);
Serial.print(".");
}
Serial.println("Ok\n");
digitalWrite(dPin[0], 0); //indicate wifi connected - white LED
I feel I should be doing a reconnect inside the "disconnectedEventHandler" - or inside my loop() but not sure exactly how. Full sketch attached for context