[SOLVED] Time out if there is physical no access point available?

Dear all,
my project works fine if the ESP8266 is connected to the access point.

But I have a simple question.
In some cases the access point is not present because I´m out of office.
In that cases my project blocks after reset because it can´t connect .

My question is if there is a possibility to have a timeout if it can´t connect ?
Or do you have another idea how to fix if the access point is physical not present

I want to start in that case an alternative program which does not use WIFI

It depends which Wi-Fi library you’re using, but you’ll probably find that you can use WIFI.status() to find out if you’re connected to an access point, if WL_CONNECTED is true then you have a connection.

You could use a simple timer to periodically check if you have a connection and do something if not.
You might want to have a few attempts at re-connecting before you get your code to go off and do something else, just incase you are within range but the Wi-Fi signal was dropped for some reason.
You might also want to keep trying periodic reconnections during the code you run when you don’t have a connection, so that once you get back within range of Wi-Fi you’ll reconnect automatically.

If you are travelling between two different Wi-Fi SSID’s then you could have your code try to connect to one, and if you don’t get a connection after a few attempts (!WL_CONNECTED) then try a second, third, fourth set of credentials.

Pete.

1 Like

Thank you for your help.
And yes this is what I´m looking for.

But I think that I can´t use the function if WL_CONNECTED
because I need to know if the access point is present before I try to connect to.
Otherwise the line Blynk.begin(auth, ssid, pass); will block

Im using:

..include <ESP8266WiFi.h>
..include <BlynkSimpleEsp8266.h>

setup() ....
Blynk.begin(auth, ssid, pass); // this line blocks if there is no connection it will wait for ever until it connects

Hmm, sorry - I kind of forgot that this was the Blynk forum!
In my defence, I use Blynk in a different way to most people - I use a Pi and Node-Red to talk to Blynk then MQTT to talk to my ESP devices, so my ESP’s don’t actually run any Blynk specific code :slight_smile:

Looking at the Blynk documentation, it looks like you can use Blynk.connected() to check if you already have a connection and maybe Blynk.connect() instead of Blynk.begin() as it has a default connection timeout of 30 seconds.

Pete.

1 Like

Yes thank you this is exactly what I´m looking for. I have not recognize it.
Thank you so much.

1 Like