[X] I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
[X] I have searched the issue tracker for a similar issue and not found a similar issue.
IDF version.
v4.4.2
Operating System used.
Windows
How did you build your project?
Eclipse IDE
If you are using Windows, please specify command line type.
None
Development Kit.
ESP32-Wrover E Rev 3
Power Supply used.
External 3.3V
What is the expected behavior?
I expect aws to re-connect back to AWS when there is a network or internet disconnection and re-connection.
What is the actual behavior?
It is not able to manually reconnect my device to AWS after there is a network disconnection issue.
Steps to reproduce.
Step 1- Connect ESP to AWS once.
Step 2- Disconnect the internet from the WiFi Router.
Step 3 - Reconnect it back after sometime.
Step 4 - Do Step 2 and 3, three to four times.
AWS initialization code
`/**
@fn int phy_mqtt_client_initialize(aws_cert_t *cert)
@brief Initializes the MQTT client with the AWS certificate.
This function initializes the MQTT client using the AWS certificate.
@param cert Pointer to the AWS certificate structure.
@return Returns 0 on success, or a negative value indicating an error.
/
int phy_mqtt_client_initialize(aws_cert_t cert)
{
IoT_Error_t rc = FAILURE;
IoT_Client_Init_Params mqttInitParams = iotClientInitParamsDefault;
IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault;
log_info(AWS, "%s : AWS IoT SDK Version %d.%d.%d-%s", func, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
I (10:21:25.371) AWS: aws_iot_publish : MQTT PUBLISH SUCCESS
I (10:21:25.390) AWS: aws_iot_publish : MQTT PUBLISH SUCCESS
I (10:21:25.414) AWS: aws_iot_publish : MQTT PUBLISH SUCCESS
I (10:21:25.431) AWS: aws_iot_publish : MQTT PUBLISH SUCCESS
I (10:21:25.779) AWS: aws_iot_publish : MQTT PUBLISH SUCCESS
W (1695505) wifi:<ba-add>idx:1 (ifx:0, b2:56:38:8d:df:c4), tid:7, ssn:1, winSize:64
E (10:21:42.847) AWS: disconnectCallbackHandler : MQTT Disconnect
I (10:21:42.847) PHY_INDICATOR: phy_indicator_set_state : indicator_state = 2
I (10:21:42.849) PHY_INDICATOR: phy_indicator_set_state : Hal_Create_Thread_Orange_Indicator_Blink
D (10:21:42.859) aws_iot: Seeding the random number generator...
D (10:21:42.869) aws_iot: Loading embedded CA root certificate ...
D (10:21:42.876) aws_iot: ok (0 skipped)
D (10:21:42.876) aws_iot: Loading embedded client certificate...
D (10:21:42.887) aws_iot: Loading embedded client private key...
D (10:21:42.895) aws_iot: ok
D (10:21:42.895) aws_iot: Connecting to ....ap-south-1.amazonaws.com/8883...
D (10:21:47.171) aws_iot: ok
D (10:21:47.172) aws_iot: Setting up the SSL/TLS structure...
D (10:21:47.177) aws_iot: SSL state connect : 0
D (10:21:47.178) aws_iot: ok
D (10:21:47.178) aws_iot: SSL state connect : 0
D (10:21:47.180) aws_iot: Performing the SSL/TLS handshake...
D (10:21:47.455) aws_iot: Verify requested for (Depth 2):
D (10:21:47.456) aws_iot: cert. version : 3
serial number : 06:6C:9F:CF:99:BF:8C:0A:39:E2:F0:78
issuer name : C=US, O=Amazon, CN=Amazon Root CA 1
subject name : C=US, O=Amazon, CN=Amazon Root CA 1
issued on : 2015-05-26 00:00:00
exp
D (10:21:47.474) aws_iot: This certificate has no flags
D (10:21:47.480) aws_iot: Verify requested for (Depth 1):
D (10:21:47.485) aws_iot: cert. version : 3
serial number : 07:73:12:38:0B:9D:66:88:A3:3B:1E:D9:BF:A6:8E:0E:0F
issuer name : C=US, O=Amazon, CN=Amazon Root CA 1
subject name : C=US, O=Amazon, CN=Amazon RSA 2048 M01
issued on : 2022-08-23 22:21:28
D (10:21:47.510) aws_iot: This certificate has no flags
D (10:21:47.515) aws_iot: Verify requested for (Depth 0):
D (10:21:47.520) aws_iot: cert. version : 3
serial number : 0E:DC:9F:18:47:FF:BA:74:E5:D4:68:4C:57:AA:3C:D9
issuer name : C=US, O=Amazon, CN=Amazon RSA 2048 M01
subject name : CN=*.iot.ap-south-1.amazonaws.com
issued on : 2023-02-27 00:00:00
expires on
D (10:21:47.545) aws_iot: This certificate has no flags
D (10:21:49.186) aws_iot: ok [ Protocol is TLSv1.2 ] [ Ciphersuite is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 ]
D (10:21:49.187) aws_iot: [ Record expansion is 29 ]
D (10:21:49.191) aws_iot: Verifying peer X.509 certificate...
D (10:21:49.196) aws_iot: ok
D (10:21:49.199) aws_iot: Peer certificate information:
D (10:21:49.204) aws_iot: cert. version : 3
serial number : 0E:DC:9F:18:47:FF:BA:74:E5:DC:57:AA:3C:D9
issuer name : C=US, O=Amazon, CN=Amazon RSA 2048 M01
subject name : CN=*.iot.ap-south-1.amazonaws.com
issued on : 2
D (10:22:02.068) esp_netif_lwip: esp_netif_ip_lost_timer esp_netif:0x3ffb5c80
D (10:22:02.068) esp_netif_lwip: if0x3ffb5c80 ip lost tmr: no need raise ip lost event
E (10:22:09.348) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:14.350) aws_iot: failed
! mbedtls_ssl_write returned -0x50
E (10:22:14.350) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:19.349) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:19.349) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:24.349) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:24.349) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:29.348) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:29.349) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:34.348) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:34.349) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:39.349) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:39.349) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:44.348) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:44.349) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:49.349) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:49.349) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:54.349) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:54.350) AWS: Phy_AWS_IoT_Task : Manual Reconnect Failed - 4
E (10:22:59.349) aws_iot: failed
! mbedtls_ssl_write returned -0x4e
E (10:22:59.349) AWS: Phy_AWS_IoT_T
Answers checklist.
IDF version.
v4.4.2
Operating System used.
Windows
How did you build your project?
Eclipse IDE
If you are using Windows, please specify command line type.
None
Development Kit.
ESP32-Wrover E Rev 3
Power Supply used.
External 3.3V
What is the expected behavior?
I expect aws to re-connect back to AWS when there is a network or internet disconnection and re-connection.
What is the actual behavior?
It is not able to manually reconnect my device to AWS after there is a network disconnection issue.
Steps to reproduce.
Step 1- Connect ESP to AWS once. Step 2- Disconnect the internet from the WiFi Router. Step 3 - Reconnect it back after sometime. Step 4 - Do Step 2 and 3, three to four times.
AWS initialization code `/**
@return Returns 0 on success, or a negative value indicating an error. / int phy_mqtt_client_initialize(aws_cert_t cert) { IoT_Error_t rc = FAILURE; IoT_Client_Init_Params mqttInitParams = iotClientInitParamsDefault; IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault; log_info(AWS, "%s : AWS IoT SDK Version %d.%d.%d-%s", func, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
mqttInitParams.enableAutoReconnect = false; // We enable this later below mqttInitParams.pHostURL = config.hostURL; mqttInitParams.port = AWS_IOT_MQTT_PORT; mqttInitParams.pRootCALocation = cert->root_ca; mqttInitParams.pDeviceCertLocation = cert->cert_pem; mqttInitParams.pDevicePrivateKeyLocation = cert->private_key; mqttInitParams.mqttCommandTimeout_ms = 20000; mqttInitParams.tlsHandshakeTimeout_ms = 20000; mqttInitParams.isSSLHostnameVerify = true; mqttInitParams.disconnectHandler = disconnectCallbackHandler; mqttInitParams.disconnectHandlerData = NULL;
rc = aws_iot_mqtt_init(&mqttClient, &mqttInitParams); if(SUCCESS != rc) { log_error(AWS, "%s : AWS IoT MQTT Init failed : %d", func, rc); return rc; }
log_info(AWS, "%s : AWS IoT MQTT Init success", func);
connectParams.keepAliveIntervalInSec = 10; connectParams.isCleanSession = true; connectParams.MQTTVersion = MQTT_3_1_1; connectParams.pClientID = config.thingName; connectParams.clientIDLen = (uint16_t) strlen(config.thingName); connectParams.isWillMsgPresent = false;
do { rc = aws_iot_mqtt_connect(&mqttClient, &connectParams); if(SUCCESS != rc) { log_error(AWS, "Error(%d) connecting to %s:%d", rc, mqttInitParams.pHostURL, mqttInitParams.port); vTaskDelay(1000 / portTICK_RATE_MS); } else { aws_event_callback.state = AWS_IOT_CONNECTED; break; } } while(SUCCESS != rc);
log_info(AWS, "%s : aws connection status : %d", func, rc); return rc; }`
Aws reconnection code
if(aws_event_callback.state == AWS_IOT_RECONNECTING) { aws_event_callback.state = AWS_IOT_RECONNECT; event_handler(aws_event_callback); do { rc = aws_iot_mqtt_attempt_reconnect(&mqttClient); if(NETWORK_RECONNECTED == rc || NETWORK_ALREADY_CONNECTED_ERROR == rc) { log_info(AWS, "%s : Manual Reconnect Successful", func); } else { uint8_t job_state = aws_jobs_get_state(); if(job_state == JOB_EXECUTION_FAILED || job_state == JOB_EXECUTION_IN_PROGRESS) { aws_jobs_publish(&mqttClient, "invalid image", event_handler); } log_error(AWS, "%s : Manual Reconnect Failed - %d", func, rc); vTaskDelay(5000 / portTICK_RATE_MS); } } while(NETWORK_RECONNECTED != rc); }
Debug Logs.
More Information.
ESP IDF Branch - release/v4.4.2 esp_aws_iot Branch - release/3.1x