WiFi/Internet KeepAlive - How to property maintain network connection without reboots?

RMandR
Posts: 75
Joined: Mon Oct 29, 2018 3:13 pm

WiFi/Internet KeepAlive - How to property maintain network connection without reboots?

Postby RMandR » Tue Nov 10, 2020 12:58 am

My application easily connects to the WiFi AP and the AWS IOT endpoint.

This is all good, but after a few days, the device can lose wifi or IOT connection (due to power, or internet outage, AP not being always on, etc).

The docs suggests that it is up to the "application" to maintain connectivity.

What is the proper process of maintaining and re-trying connections?

Would really appreciate pointers on how to maintain a solid connection to the wifi network as well as the cloud endpoints.

-a

Gardin
Posts: 31
Joined: Fri Dec 13, 2019 4:53 pm

Re: WiFi/Internet KeepAlive - How to property maintain network connection without reboots?

Postby Gardin » Tue Nov 10, 2020 2:24 pm

When you set up Wi-Fi you generally set an event group to signal Wi-Fi events.

From there you can try to reconnect to the Wi-Fi in case of a disconnection.

take a look in this example:

https://github.com/espressif/esp-idf/tr ... ed/station

In case you are using aws-iot-device-sdk-embedded-C the aws connection should be maintained using:

Code: Select all

rc = aws_iot_mqtt_autoreconnect_set_status(&client, true);

RMandR
Posts: 75
Joined: Mon Oct 29, 2018 3:13 pm

Re: WiFi/Internet KeepAlive - How to property maintain network connection without reboots?

Postby RMandR » Wed Nov 11, 2020 3:28 pm

thanks @Gardin

In their code, they retry a few times and then give up:

Code: Select all

if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {esp_wifi_connect();s_retry_num++;ESP_LOGI(TAG, "retry to connect to the AP");} else {xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);}ESP_LOGI(TAG,"connect to the AP fail");
The above logic fails if the device powers up faster than your average linux based AP that takes minutes to come online. It also stays permanently disconnected if the wifi ap is powered say an hour after the esp32 has gone through its retries.

Presumably, one can make infinite retries, but I'm not sure if that is a hack or a solution.

Who is online

Users browsing this forum: Assasinsareus, terpstraapril, Valter and 120 guests