wifi connect and disconnect to my will

Nasib Fahim
Posts: 11
Joined: Wed Jun 23, 2021 2:22 pm

wifi connect and disconnect to my will

Postby Nasib Fahim » Wed Jun 30, 2021 4:50 pm

I am using the simplest wifi station example... i am passing the WIFI usr and pass through uart to the esp32s2. the first time i pass those values to the board, everything is ok. But now i want to pass again those values while the board is connected to wifi.. so i guess i need to disconnect the board from wifi and then connect it again with the new usr and pass..

But i dont know how to disconnect the board from the wifi...

Could anybody help me here?


Thank you so so much in advance

Best regards
:D :D

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

Re: wifi connect and disconnect to my will

Postby mbratch » Thu Jul 01, 2021 2:18 am

You should be able to do `esp_wifi_disconnect()`, reconfigure the wifi with the new credentials and info, then `esp_wifi_connect()`. If your event handler is written like the example, it should go through the connection and authentication process again.
Last edited by mbratch on Fri Jul 02, 2021 2:24 am, edited 1 time in total.

Nasib Fahim
Posts: 11
Joined: Wed Jun 23, 2021 2:22 pm

Re: wifi connect and disconnect to my will

Postby Nasib Fahim » Thu Jul 01, 2021 11:49 am

Thank you so much for your response.

I use exactly the same functions as in wifi station example idf.

I did this:

esp_wifi_stop();
wifi_init_sta();
esp_wifi_start();

But the system reboots with the following info:



I (32410) wifi:state: run -> init (0)
I (32410) wifi:pm stop, total sleep time: 17494143 us / 30438569 us

I (32410) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
W (32420) wifi:hmac tx: stop, discard
W (32420) wifi:hmac tx: stop, discard
I (33460) wifi:flush txq
I (33460) wifi:stop sw txq
I (33460) wifi:lmac stop hw txq
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x4002a350
0x4002a350: _esp_error_check_failed at C:/Users/Nasib/Desktop/esp-idf/components
/esp_common/src/esp_err.c:45

file: "../main/gpio_example_main.c" line 533
func: wifi_init_sta
expression: esp_event_loop_create_default()

abort() was called at PC 0x4002a353 on core 0
0x4002a353: _esp_error_check_failed at C:/Users/Nasib/Desktop/esp-idf/components
/esp_common/src/esp_err.c:46


Backtrace:0x4002b493:0x3ffd3f90 0x4002bccd:0x3ffd3fb0 0x40031faa:0x3ffd3fd0 0x40
02a353:0x3ffd4040 0x4008607b:0x3ffd4060 0x400869a7:0x3ffd41c0 0x40084163:0x3ffd4
220 0x4002bcd5:0x3ffd4250
0x4002b493: panic_abort at C:/Users/Nasib/Desktop/esp-idf/components/esp_system/
panic.c:330

0x4002bccd: esp_system_abort at C:/Users/Nasib/Desktop/esp-idf/components/esp_sy
stem/system_api.c:106

0x40031faa: abort at C:/Users/Nasib/Desktop/esp-idf/components/newlib/abort.c:46

0x4002a353: _esp_error_check_failed at C:/Users/Nasib/Desktop/esp-idf/components
/esp_common/src/esp_err.c:46

0x4008607b: wifi_init_sta at C:\Users\Nasib\eclipse-workspace\gpio\build/../main
/gpio_example_main.c:533 (discriminator 1)

0x400869a7: app_main at C:\Users\Nasib\eclipse-workspace\gpio\build/../main/gpio
_example_main.c:1034

0x40084163: main_task at C:/Users/Nasib/Desktop/esp-idf/components/esp32s2/cpu_s
tart.c:453 (discriminator 2)

0x4002bcd5: vPortTaskWrapper at C:/Users/Nasib/Desktop/esp-idf/components/freert
os/xtensa/port.c:143



ELF file SHA256: 04f8503afd36ced3

Rebooting...

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

Re: wifi connect and disconnect to my will

Postby mbratch » Thu Jul 01, 2021 10:45 pm

You shouldn't have to go through the entire event creation and initialization process. `wifi_init_sta()` was written with the intention of being called during initialization. I think you just need to:

Code: Select all

esp_wifi_disconnect();
esp_wifi_set_config(...);
esp_wifi_connect();
And the event handler would handle the rest.

Nasib Fahim
Posts: 11
Joined: Wed Jun 23, 2021 2:22 pm

Re: wifi connect and disconnect to my will

Postby Nasib Fahim » Fri Jul 02, 2021 9:36 am

Thank you so much for your answer. This is still a challenge. If i am connected to a network with one pass and one usr. I can use those functions perfectly.. but if i want to change to another network (changing the usr and pass.. ) and i use those functions the system reboots...

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

Re: wifi connect and disconnect to my will

Postby mbratch » Fri Jul 02, 2021 1:35 pm

What does your monitor show in that case, leading up to the reboot? It should log the wifi events. You may have some other error in the code causing a reboot. There's often a log message indicating why the reboot is occurring.

Who is online

Users browsing this forum: Gaston1980 and 113 guests