Can't switch from WiFi AP mode to STA mode

fmuller-pi

Can't switch from WiFi AP mode to STA mode

Postby fmuller-pi » Fri Feb 15, 2019 2:17 am

Hi,

I am using the version 3.1 (the most up to date in the release branch) of the ESP8266_RTOS_SDK. For my project, I start the application by setting the ESP8266 to AP mode, so that I can connect to it with my phone. Then, once I got the network credentials, I want to shut down the AP mode and go into STA mode using those credentials. The problem is that it doesn't work. The credentials are well received, but the switch between AP to STA mode just doesn't work...
I was previously using the version 2.x.x of that SDK, and there I was able to get it to work fine. But I just updated to the version 3.1 for security reason linked to FreeRTOS, and the WiFi APIs changed quite a lot. So, following the few example from Espressif available, I tried to write the code for my application to do that switch between AP and STA but it doesn't work.
I tried everything: stopping the wifi and restarting it between the two modes; stopping + de-initializing between the switch; just change the opmode without stopping the wifi... Anyway, nothing seems to be working. My AP mode works just fine, but the problem happens at the STA mode, it just keeps on entering into the event SYSTEM_EVENT_STA_DISCONNECTED... There I call esp_wifi_connect() (like shown in the SDK example), but it doesn't work. reenter again and again the SYSTEM_EVENT_STA_DISCONNECTED event. My mode is set to STA, I got the right network credentials, and my local network is working. So I don't know what is the issue and it is becoming very hard to find new things to try to fix this.
NOTE: I really don't wanna set my ESP8266 to dual AP+STA mode, I just want to set it to AP when needed, and then shut down the AP mode and go into full STA mode.

Please, if anyone has anything that I could try, let me know :)

fmuller-pi

Re: Can't switch from WiFi AP mode to STA mode

Postby fmuller-pi » Sun Feb 17, 2019 5:38 am

I am self-answering myself here. The issue came from the fact that I was not initializing the structure wifi_config_t to 0 (i.e. like this: structurewifi_config_t config = {0}). So because I was then using it and filling the SSID and password, but that the rest was randomly set, it created some issues with my STA mode.

Anyway, all works fine for now :)

Who is online

Users browsing this forum: No registered users and 279 guests