Connection always disconnecting

f.h-f.s.
Posts: 215
Joined: Thu Dec 08, 2016 2:53 pm

Connection always disconnecting

Postby f.h-f.s. » Fri Dec 09, 2016 8:28 am

Hello ESP32 Community,

I recently acquired an esp32, a pycom LoPy yay.
I am trying to connect to a wifi network with my esp32 but it always seems to disconnect.
I used the IDF example https_request.
The code catches the events: SYSTEM_EVENT_STA_START, CONNECTED, GOT_IP, and DISCONNECTED.
The reason for disconnecting is
201(WIFI_REASON_NO_AP_FOUND) or 2(WIFI_REASON_AUTH_EXPIRE) these occur very often,
3(WIFI_REASON_AUTH_LEAVE) or 4(WIFI_REASON_ASSOC_EXPIRE) occurs when it connects but then disconnect.

I also tried my phone as an accesspoint instead of my router, same results.
Any help would be appreciated!

The wifi state jumps from 0 to 2 and 2 to 0 alot and sometimes it does connect(jumps to 3 and somtimes 5) , but this doesn't last.
My serial output:

Code: Select all

D (101626) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:64:bc:0c:82:0f:91, reason:2[0m
V (101626) event: enter default callback[0m
V (101636) event: exit default callback[0m
[0;32mI (101636) example: disconnect reason: 2[0m
[0;32mI (101646) example: reconnected Ok or error: 0, authmode: 0[0m
I (102516) wifi: n:6 0, o:6 0, ap:255 255, sta:6 0, prof:1
I (102516) wifi: state: 0 -> 2 (b0)
I (103516) wifi: state: 2 -> 0 (2)
D (103516) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:64:bc:0c:82:0f:91, reason:2[0m
V (103516) event: enter default callback[0m
V (103516) event: exit default callback[0m
[0;32mI (103526) example: disconnect reason: 2[0m
[0;32mI (103526) example: reconnected Ok or error: 0, authmode: 0[0m
D (105636) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:00:00:00:00:00:00, reason:201[0m
V (105636) event: enter default callback[0m
V (105636) event: exit default callback[0m
[0;32mI (105646) example: disconnect reason: 201[0m
[0;32mI (105646) example: reconnected Ok or error: 0, authmode: 81[0m
I (106516) wifi: n:6 0, o:6 0, ap:255 255, sta:6 0, prof:1
I (106516) wifi: state: 0 -> 2 (b0)
I (106526) wifi: state: 2 -> 3 (0)
I (106586) wifi: state: 3 -> 5 (10)
I (109676) wifi: connected with Gadfhfss, channel 6
D (109676) event: SYSTEM_EVENT_STA_CONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:64:bc:0c:82:0f:91, channel:6, authmode:3[0m
V (109686) event: enter default callback[0m
V (109686) event: exit default callback[0m
[0;32mI (109696) example: connected! ip = 1717854535[0m
I (113616) wifi: state: 5 -> 2 (3a0)
I (113616) wifi: n:6 0, o:6 0, ap:255 255, sta:6 0, prof:1
D (113616) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:64:bc:0c:82:0f:91, reason:3[0m
V (113626) event: enter default callback[0m
V (113626) event: exit default callback[0m
The wifi initialization

Code: Select all

static void initialise_wifi(void)
{
    tcpip_adapter_init();
    wifi_event_group = xEventGroupCreate();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    wifi_config_t wifi_config = {
        .sta = {
            .ssid = EXAMPLE_WIFI_SSID,
            .password = EXAMPLE_WIFI_PASS,
        },
    };
    ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
}
The event handler

Code: Select all

static esp_err_t event_handler(void *ctx, system_event_t *event)
{
	int32_t eet;
    switch(event->event_id) {
    case SYSTEM_EVENT_STA_START:
	    eet = esp_wifi_connect();
	    ESP_LOGI(TAG, "Ok or error: %d, authmode: %d", eet, event->event_info.connected.authmode);
        break;
    case SYSTEM_EVENT_STA_CONNECTED:
	    ESP_LOGI(TAG, "connected! ip = %d", event->event_info.got_ip.ip_info.ip.addr);
	    break;
    case SYSTEM_EVENT_STA_GOT_IP:
	    //not yet
	    ESP_LOGI(TAG, "ip = %d", event->event_info.got_ip.ip_info.ip.addr);
        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
        break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
        /* This is a workaround as ESP32 WiFi libs don't currently
           auto-reassociate. */
	    ESP_LOGI(TAG, "disconnect reason: %d", event->event_info.disconnected.reason);
	    eet = esp_wifi_connect();
	    ESP_LOGI(TAG, "reconnected Ok or error: %d, authmode: %d", eet, event->event_info.connected.authmode);
        xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
        break;
    default:
	    ESP_LOGI(TAG, "Other system event %d...", event->event_info.connected.authmode );
        break;
    }
    return ESP_OK;
}

f.h-f.s.
Posts: 215
Joined: Thu Dec 08, 2016 2:53 pm

Re: Connection always disconnecting

Postby f.h-f.s. » Mon Dec 12, 2016 9:38 am

The pycom has a antenna connector. When using AP mode I was able to connect without an antenna. I wrongly assumed I could leave the antenna behind. Problem fixed. *ashamed*

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Connection always disconnecting

Postby Ritesh » Mon Jan 30, 2017 10:16 am

f.h-f.s. wrote:Hello ESP32 Community,

I recently acquired an esp32, a pycom LoPy yay.
I am trying to connect to a wifi network with my esp32 but it always seems to disconnect.
I used the IDF example https_request.
The code catches the events: SYSTEM_EVENT_STA_START, CONNECTED, GOT_IP, and DISCONNECTED.
The reason for disconnecting is
201(WIFI_REASON_NO_AP_FOUND) or 2(WIFI_REASON_AUTH_EXPIRE) these occur very often,
3(WIFI_REASON_AUTH_LEAVE) or 4(WIFI_REASON_ASSOC_EXPIRE) occurs when it connects but then disconnect.

I also tried my phone as an accesspoint instead of my router, same results.
Any help would be appreciated!

The wifi state jumps from 0 to 2 and 2 to 0 alot and sometimes it does connect(jumps to 3 and somtimes 5) , but this doesn't last.
My serial output:

Code: Select all

D (101626) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:64:bc:0c:82:0f:91, reason:2[0m
V (101626) event: enter default callback[0m
V (101636) event: exit default callback[0m
[0;32mI (101636) example: disconnect reason: 2[0m
[0;32mI (101646) example: reconnected Ok or error: 0, authmode: 0[0m
I (102516) wifi: n:6 0, o:6 0, ap:255 255, sta:6 0, prof:1
I (102516) wifi: state: 0 -> 2 (b0)
I (103516) wifi: state: 2 -> 0 (2)
D (103516) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:64:bc:0c:82:0f:91, reason:2[0m
V (103516) event: enter default callback[0m
V (103516) event: exit default callback[0m
[0;32mI (103526) example: disconnect reason: 2[0m
[0;32mI (103526) example: reconnected Ok or error: 0, authmode: 0[0m
D (105636) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:00:00:00:00:00:00, reason:201[0m
V (105636) event: enter default callback[0m
V (105636) event: exit default callback[0m
[0;32mI (105646) example: disconnect reason: 201[0m
[0;32mI (105646) example: reconnected Ok or error: 0, authmode: 81[0m
I (106516) wifi: n:6 0, o:6 0, ap:255 255, sta:6 0, prof:1
I (106516) wifi: state: 0 -> 2 (b0)
I (106526) wifi: state: 2 -> 3 (0)
I (106586) wifi: state: 3 -> 5 (10)
I (109676) wifi: connected with Gadfhfss, channel 6
D (109676) event: SYSTEM_EVENT_STA_CONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:64:bc:0c:82:0f:91, channel:6, authmode:3[0m
V (109686) event: enter default callback[0m
V (109686) event: exit default callback[0m
[0;32mI (109696) example: connected! ip = 1717854535[0m
I (113616) wifi: state: 5 -> 2 (3a0)
I (113616) wifi: n:6 0, o:6 0, ap:255 255, sta:6 0, prof:1
D (113616) event: SYSTEM_EVENT_STA_DISCONNECTED, ssid:Gadfhfss, ssid_len:8, bssid:64:bc:0c:82:0f:91, reason:3[0m
V (113626) event: enter default callback[0m
V (113626) event: exit default callback[0m
The wifi initialization

Code: Select all

static void initialise_wifi(void)
{
    tcpip_adapter_init();
    wifi_event_group = xEventGroupCreate();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    wifi_config_t wifi_config = {
        .sta = {
            .ssid = EXAMPLE_WIFI_SSID,
            .password = EXAMPLE_WIFI_PASS,
        },
    };
    ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
}
The event handler

Code: Select all

static esp_err_t event_handler(void *ctx, system_event_t *event)
{
	int32_t eet;
    switch(event->event_id) {
    case SYSTEM_EVENT_STA_START:
	    eet = esp_wifi_connect();
	    ESP_LOGI(TAG, "Ok or error: %d, authmode: %d", eet, event->event_info.connected.authmode);
        break;
    case SYSTEM_EVENT_STA_CONNECTED:
	    ESP_LOGI(TAG, "connected! ip = %d", event->event_info.got_ip.ip_info.ip.addr);
	    break;
    case SYSTEM_EVENT_STA_GOT_IP:
	    //not yet
	    ESP_LOGI(TAG, "ip = %d", event->event_info.got_ip.ip_info.ip.addr);
        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
        break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
        /* This is a workaround as ESP32 WiFi libs don't currently
           auto-reassociate. */
	    ESP_LOGI(TAG, "disconnect reason: %d", event->event_info.disconnected.reason);
	    eet = esp_wifi_connect();
	    ESP_LOGI(TAG, "reconnected Ok or error: %d, authmode: %d", eet, event->event_info.connected.authmode);
        xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
        break;
    default:
	    ESP_LOGI(TAG, "Other system event %d...", event->event_info.connected.authmode );
        break;
    }
    return ESP_OK;
}
Hi,

Did you get any solution for your issue? because, I am also getting WIFI_REASON_AUTH_EXPIRE for 2 of boards in which STA is disconnected continuously and not able to detect device into AP mode.

Let me know if you have any clue or solution for that
Regards,
Ritesh Prajapati

f.h-f.s.
Posts: 215
Joined: Thu Dec 08, 2016 2:53 pm

Re: Connection always disconnecting

Postby f.h-f.s. » Mon Jan 30, 2017 11:34 am

Hi Ritesh,

My issue was caused by not attaching an antenna. The pycom lopy doesn't have an antenna on its pcb I'm guessing.

I was able to connect to the lopy when it was in AP mode.

What board are you using? Are you following an example?

Goodluck.

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Connection always disconnecting

Postby Ritesh » Mon Jan 30, 2017 11:47 am

f.h-f.s. wrote:Hi Ritesh,

My issue was caused by not attaching an antenna. The pycom lopy doesn't have an antenna on its pcb I'm guessing.

I was able to connect to the lopy when it was in AP mode.

What board are you using? Are you following an example?

Goodluck.
I am using ESP32 chip for my product development and code which i followed is standard WiFi connection in AP and STA mode. I have checked that code which is working fine into other same board with ESP32 chip.

So, It seems like there is no any fault into code perspective as it is working into other boards. I have total 30 ESP32 chip and getting AP+STA WiFi not working issue into 2 of ESP32 chip out of 30 Chip.

Let me know if you need any further informations from my side.
Regards,
Ritesh Prajapati

vateriim
Posts: 4
Joined: Thu Jan 25, 2018 6:11 pm

Re: Connection always disconnecting

Postby vateriim » Thu Jan 25, 2018 6:15 pm

Hi Ritesh,

Did you have any success with this issue?
I am in a very similar situation, 15% of my devices have a *random* Connection issue after a few days in the field. Reasons 2, 4, 6, 200, 201 and 205.
Best regards

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Connection always disconnecting

Postby Ritesh » Fri Jan 26, 2018 1:46 pm

vateriim wrote:Hi Ritesh,

Did you have any success with this issue?
I am in a very similar situation, 15% of my devices have a *random* Connection issue after a few days in the field. Reasons 2, 4, 6, 200, 201 and 205.
Best regards
Hi,

We have tried to debug with all possible test-cases and found issue into hardware side.

There was one Crystal nearer to ESP32 which was for WiFi seems to be not connected properly.

So, After reworking if from hardware side it was working fine without any issue into both boards.

So, There might be issue into hardware side in your case as well. Please check it from hardware side as well.
Regards,
Ritesh Prajapati

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Connection always disconnecting

Postby Ritesh » Sat Jan 27, 2018 5:28 am

vateriim wrote:Hi Ritesh,

Did you have any success with this issue?
I am in a very similar situation, 15% of my devices have a *random* Connection issue after a few days in the field. Reasons 2, 4, 6, 200, 201 and 205.
Best regards
Hi,

In our case there is always failure to operate device with WiFi STA or AP Interface. So, There might be something different issue in your case if it was working fine before and then creating issue in later stage.
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: Baoshi and 74 guests