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
WiFi/Internet KeepAlive - How to property maintain network connection without reboots?
Re: WiFi/Internet KeepAlive - How to property maintain network connection without reboots?
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:
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);
Re: WiFi/Internet KeepAlive - How to property maintain network connection without reboots?
thanks @Gardin
In their code, they retry a few times and then give up:
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.
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");
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: MichaelS and 101 guests