void disconnectCallbackHandler(void) { WARN("MQTT Disconnect"); IoT_Error_t rc = NONE_ERROR; if(aws_iot_is_autoreconnect_enabled()){ INFO("Auto Reconnect is enabled, Reconnecting attempt will start now"); }else{ WARN("Auto Reconnect not enabled. Starting manual reconnect..."); rc = aws_iot_mqtt_attempt_reconnect(); if(RECONNECT_SUCCESSFUL == rc){ WARN("Manual Reconnect Successful"); }else{ WARN("Manual Reconnect Failed - %d", rc); } } }
void disconnectCallbackHandler(AWS_IoT_Client *pClient, void *data) { ESP_LOGW(TAG, "MQTT Disconnect"); IoT_Error_t rc = FAILURE; if(NULL == pClient) { return; } if(aws_iot_is_autoreconnect_enabled(pClient)) { ESP_LOGI(TAG, "Auto Reconnect is enabled, Reconnecting attempt will start now"); } else { ESP_LOGW(TAG, "Auto Reconnect not enabled. Starting manual reconnect..."); rc = aws_iot_mqtt_attempt_reconnect(pClient); if(NETWORK_RECONNECTED == rc) { ESP_LOGW(TAG, "Manual Reconnect Successful"); } else { ESP_LOGW(TAG, "Manual Reconnect Failed - %d", rc); } } }
/* G:11 - Yield, disconnected, Manual reconnect */ TEST_C(YieldTests, disconnectManualAutoReconnect) { IoT_Error_t rc = FAILURE; unsigned char *currPayload = NULL; IOT_DEBUG("-->Running Yield Tests - G:11 - Yield, disconnected, Manual reconnect \n"); CHECK_C(aws_iot_mqtt_is_client_connected(&iotClient)); /* Disable Autoreconnect, then let ping request time out and call yield */ aws_iot_mqtt_autoreconnect_set_status(&iotClient, false); CHECK_C(!aws_iot_is_autoreconnect_enabled(&iotClient)); /* Sleep for half keep alive interval to allow the first ping to be sent out */ sleep(iotClient.clientData.keepAliveInterval / (uint32_t)2); rc = aws_iot_mqtt_yield(&iotClient, 100); CHECK_EQUAL_C_INT(SUCCESS, rc); CHECK_EQUAL_C_INT(true, isLastTLSTxMessagePingreq()); /* Let ping request time out and call yield */ sleep(iotClient.clientData.keepAliveInterval / (uint32_t)2 + 1); rc = aws_iot_mqtt_yield(&iotClient, 100); CHECK_EQUAL_C_INT(NETWORK_DISCONNECTED_ERROR, rc); CHECK_EQUAL_C_INT(1, isLastTLSTxMessageDisconnect()); CHECK_C(!aws_iot_mqtt_is_client_connected(&iotClient)); CHECK_EQUAL_C_INT(true, dcHandlerInvoked); dcHandlerInvoked = false; setTLSRxBufferForConnack(&connectParams, 0, 0); rc = aws_iot_mqtt_attempt_reconnect(&iotClient); CHECK_EQUAL_C_INT(NETWORK_RECONNECTED, rc); currPayload = connectTxBufferHeaderParser(&prfrdParams, TxBuffer.pBuffer); CHECK_C(true == isConnectTxBufFlagCorrect(&connectParams, &prfrdParams)); CHECK_C(true == isConnectTxBufPayloadCorrect(&connectParams, currPayload)); CHECK_C(aws_iot_mqtt_is_client_connected(&iotClient)); CHECK_EQUAL_C_INT(false, dcHandlerInvoked); IOT_DEBUG("-->Success - G:11 - Yield, disconnected, Manual reconnect \n"); }