Fix ota end to end
/* Common include. */
#include "iot_common.h"
+#include "iot_error.h"
/* MQTT internal include. */
#include "iot_mqtt.h"
@@ -105,26 +106,14 @@ static const char *pcStateStr[eOTA_NumAgentStates] =
void vOTAUpdateTestTask( void * pvParameters )
{
- bool status = false;
OTA_State_t eState;
+ IotMqttError_t mqttStatus;
/* Initialize common components. */
- status = IotCommon_Init();
-
- /* Initialize the MQTT library. */
- if(status == true)
- {
- if(IotMqtt_Init() != IOT_MQTT_SUCCESS)
- {
- status = false;
- configPRINTF(("Failed to initialize MQTT\n"));
- }
- }else
+ if( IotCommon_Init() == true)
{
- configPRINTF(("Failed to initialize common components\n"));
- }
-
- if(status == true)
+ /* Initialize the MQTT library. */
+ if(IotMqtt_Init() == IOT_MQTT_SUCCESS)
{
/* Set the MQTT network setup parameters. */
( void ) memset( &networkInfo, 0x00, sizeof( IotMqttNetworkInfo_t ) );
@@ -143,19 +132,25 @@ void vOTAUpdateTestTask( void * pvParameters )
#if IOT_TEST_SECURED_CONNECTION == 1
networkInfo.pNetworkCredentialInfo = ( void * ) &credentials;
#endif
-
- if( IotMqtt_Connect( &networkInfo,
- &connectInfo,
- CONN_TIMEOUT_MS,
- &mqttConnection ) != IOT_MQTT_SUCCESS)
+ }else
{
- configPRINTF(("Failed to connect MQTT\n"));
- status = false;
+ configPRINTF(("Failed to initialize MQTT\n"));
}
+ }else
+ {
+ configPRINTF(("Failed to initialize common components\n"));
}
- if(status == true)
+
+
+ for( ; ; )
+ {
+ mqttStatus = IotMqtt_Connect( &networkInfo,
+ &connectInfo,
+ CONN_TIMEOUT_MS,
+ &mqttConnection );
+ if( mqttStatus == IOT_MQTT_SUCCESS)
{
eState = OTA_AgentInit( mqttConnection, ( const uint8_t * ) ( clientcredentialIOT_THING_NAME ), App_OTACompleteCallback, ( TickType_t ) ~0 );
@@ -172,6 +167,12 @@ void vOTAUpdateTestTask( void * pvParameters )
}
IotMqtt_Disconnect( mqttConnection, false);
+ }else
+ {
+ configPRINTF(("Failed to connect MQTT with status: %d\n", mqttStatus));
+ }
+
+ vTaskDelay(ONE_SECOND_DELAY_IN_TICKS);
}
/* All done. FreeRTOS does not allow a task to run off the end of its
