WiFi.status() (Arduino function) alternative for esp-idf

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

WiFi.status() (Arduino function) alternative for esp-idf

Postby zazas321 » Mon Sep 06, 2021 8:38 am

Hello. I use basic basic esp-idf wifi example code to connect the ESP32 device to the wifi in STA mode. Some other functions that I use require the wifi connection and I want to double check whether the device sucesfully connected to the wifi. In Arduino code, you can easily do that using WiFi.status() method, but I cannot find what would be the esp-idf alternative. Pseudo code:

Code: Select all


if(wifi_connected_sucesfully){
	do_http_request()
}
else{
attemt_to_reconnect()
{

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: WiFi.status() (Arduino function) alternative for esp-idf

Postby fasani » Tue Sep 07, 2021 11:38 am

If I'm not mistaken, you can do the same having a:

bool wifiConnected = false;

And taking in account the WiFi events
you can simply set in the event that global variable:

WIFI_EVENT_STA_CONNECTED then wifiConnected = true

WIFI_EVENT_STA_DISCONNECTED then wifiConnected = false

If there is another way please enlighten me. But otherwise this just adding 3 lines and checking for the wifiConnected state.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

microwrk234
Posts: 4
Joined: Tue Nov 22, 2022 11:25 am

Re: WiFi.status() (Arduino function) alternative for esp-idf

Postby microwrk234 » Fri Nov 25, 2022 4:15 am

This works please look the attached file
Attachments
station_example_to_check_wifi_connection_status.c
(2.62 KiB) Downloaded 453 times

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: WiFi.status() (Arduino function) alternative for esp-idf

Postby mbratch » Sun Nov 27, 2022 12:34 am

If the example you are following is the "station" under "getting started", then just look at what the event handler is doing in that example. When a connection is made, it sets the `WIFI_CONNECTED_BIT` in the `s_wifi_event_group` event group. To determine if there's a connection, check the `WIFI_CONNECT_BIT` in that event group.

Who is online

Users browsing this forum: aygh4266 and 104 guests