How to check if the NodeMCU ESP32 is connected to WiFi?

I have currently integrated an IoT system into a project using the NodeMCU ESP32. The ESP32 speaks to a Firebase RTDB and that information is further received by a website where the data is displayed. For the website, I am now building a troubleshooting mode to check the status of the various sensors in play e.g. an IR sensor. If certain things are not working as expected, the troubleshooting system would notify the user.

I am trying to figure out how I might go about checking the WiFi status of the ESP32? I understand that in the code you can do:

WiFi.status() != WL_CONNECTED

But I am wondering if the ESP32 is unable to connect to the WiFi, how might I receive this information? Without connecting to the WiFi, the ESP32 cannot speak to Firebase. Is there a solution to this? Is there a way I might be able to check the WiFi network to see if the ESP32 has joined?

Thanks!

Edit 1: I would like to add an example. I have an Air Purifier that can be controlled via my phone through an app. If the Air Purifier is off, my phone knows that it is off. I would like to do something similar. How might I go about this?

I use the following to check for a WiFI connection:

if ( (wifiClient.connected()) && (WiFi.status() == WL_CONNECTED) )

If you assign an ip address on your router to the esp32 you could then have some other device ping it to see if it is connected?

1 Like

That's an interesting method, I will research into this. Thank you!

Thanks! This is similar to what I am doing. My question is pertaining to something else though. I am trying to figure out a way to detect whether or not the NodeMCU ESP32 is connected to WiFi through my website.

ping it.

1 Like

I will give this a go

Alternatively, could you have the esp32 periodically request a page on your web site which contains Javascript or PHP which records when this last occurred?
or look in to using https://ifttt.com/ ?