ESP 32 does not connect to wifi, AUTH EXPIRE error.
Posted: Fri Apr 28, 2023 4:24 am
- int scanNconnectWifi() {
- ESP_ERROR_CHECK(esp_netif_init());
- sta_netif = esp_netif_create_default_wifi_sta();
- assert(sta_netif);
- wifi_init_config_t wifi_config = WIFI_INIT_CONFIG_DEFAULT();
- ESP_ERROR_CHECK(esp_wifi_init(&wifi_config));
- ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
- ESP_EVENT_ANY_ID,
- &event_handler,
- NULL,
- NULL));
- ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
- ESP_EVENT_ANY_ID,
- &event_handler,
- NULL,
- NULL));
- wifi_country_t wifi_country = {
- .cc = "IN",
- .schan = 1,
- .nchan = 11,
- };
- ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE) );
- ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
- ESP_ERROR_CHECK(esp_wifi_set_country(&wifi_country));
- ESP_ERROR_CHECK(esp_wifi_start() );
- ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE) );
- wifi_cred_list=loadWifiCred();
- act=NET_DO_SCAN;
- while(1) {
- switch(act) {
- case NET_DO_SCAN:
- {
- wifi_scan_config_t scan_config = {
- .ssid = 0,
- .bssid = 0,
- .channel = 0,
- .show_hidden = 1,
- .scan_type = WIFI_SCAN_TYPE_PASSIVE,
- .scan_time.active.min = 80,
- .scan_time.active.max = 120,
- };
- ESP_LOGI("TEST", "In net_do_scan about to start scan\n");
- act=NET_AWAIT_SCAN_RESULT;
- esp_err_t err = esp_wifi_scan_start(&scan_config, true);
- if (err == ESP_OK) {
- g_is_scanning = true;
- }
- }
- break;
- case NET_DO_CONNECT:
- {
- wifi_config_t wifi_config = {
- .sta={
- .scan_method=WIFI_ALL_CHANNEL_SCAN,
- .sort_method=WIFI_CONNECT_AP_BY_SIGNAL,
- .threshold.rssi=0,
- .threshold.authmode=((wifi_ap_record_t *)apToConnectTo->ap)->authmode,
- },
- };
- ESP_LOGI("TEST","in NET_DO_CONNECT %s:%s", apToConnectTo->ssid, apToConnectTo->pass);
- strcpy((char *)wifi_config.sta.ssid, (const char *)apToConnectTo->ssid);
- strcpy((char *)wifi_config.sta.password, (const char *)apToConnectTo->pass);
- ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
- act=NET_AWAIT_CONNECT_RESULT;
- esp_err_t err = esp_wifi_connect();
- if (err != ESP_OK) {
- ESP_LOGW("TEST", "Connect call failed...");
- ESP_ERROR_CHECK(err);
- restartScan();
- act=NET_DO_SCAN;
- }
- }
- break;
- case NET_DO_NOTHING:
- {
- vTaskDelay(500 / portTICK_PERIOD_MS);
- break;
- }
- case NET_AWAIT_SCAN_RESULT:
- case NET_AWAIT_CONNECT_RESULT:
- default:
- break;
- }
- if(wifiConnected==true) {
- act=NET_DO_NOTHING;
- break;
- }
- }
- return 0;
- }
I (5826) TEST: WIFI EventID : 1
I (5826) TEST: ap records found : 1
I (5826) TEST: ap_list:
I (5826) TEST: ap_list[0].ssid = XXXX2-4
I (5826) TEST: cred found : XXXX2-4:xxxxxxxx
I (5836) TEST: WIFI_EVENT_SCAN_DONE
I (5876) TEST: in NET_DO_CONNECT XXXX2-4:xxxxxxxx
I (7906) wifi: new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1
I (8656) wifi:state: init -> auth (b0)
I (9656) wifi:state: auth -> init (200)
I (9656) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (9666) TEST: WIFI EventID : 5
I (9666) TEST: Disconnect reason : 2
The following are connected in my device;
GPIO 26,13,4,25 to mosfet as switch
GPIO 22,21 to I2C
19,23,18,5 to SPI
UART to 15,2; 1,3; 16,17
ESP version:
esp32 d0wdq6-v3
Please help me resolve this issue. I think, I made a reasonable search, and I have tried most solutions provided online, but to no avail.