source/MQTTOperation.c
/**
 * @brief Initializes the MQTT Paho Client, set up subscriptions and initializes the timers and tasks
 *
 * @return NONE
 */
@brief Initializes the MQTT Paho Client, set up subscriptions and initializes the timers and tasks
@return NONE
@brief Initializes the MQTT Paho Client set up subscriptions and initializes the timers and tasks @return NONE
void MQTTOperation_Init(void* pvParameters) {
	BCDS_UNUSED(pvParameters);
	Retcode_T retcode = RETCODE_OK;
	tickRateMS = (int) pdMS_TO_TICKS(MQTTCfgParser_GetStreamRate());
	if (MqttSetupInfo.IsSecure == true) {
		retcode = AppController_SyncTime();
	}
	if (RETCODE_OK == retcode) {
		do {
			retcode = MQTT_ConnectToBroker_Z(&MqttConnectInfo,
			MQTT_CONNECT_TIMEOUT_IN_MS, &MqttCredentials);
			if (RETCODE_OK != retcode) {
				LOG_AT_ERROR(
						("MQTTOperation: MQTT connection to broker failed [%hu] time, try again ... \r\n", connectAttemps ));
				connectAttemps++;
			}
		} while (RETCODE_OK != retcode && connectAttemps < 10);
		connectAttemps = 0UL;
	}
	if (RETCODE_OK == retcode) {
		LOG_AT_INFO(
				("MQTTOperation: Successfully connected to [%s:%d]\r\n", MqttConnectInfo.BrokerURL, MqttConnectInfo.BrokerPort));
		MQTTOperation_ClientPublish();
	} else {
		LOG_AT_WARNING(
				("MQTTOperation: Now calling SoftReset and reboot to recover\r\n"));
		AppController_SetAppStatus(APP_STATUS_ERROR);
		vTaskDelay(pdMS_TO_TICKS(30000));
		BSP_Board_SoftReset();
	}
}
void MQTTOperation_Init ( void * pvParameters ) { BCDS_UNUSED ( pvParameters ) ; Retcode_T retcode = RETCODE_OK ; tickRateMS = ( int ) pdMS_TO_TICKS ( MQTTCfgParser_GetStreamRate ( ) ) ; if ( MqttSetupInfo . IsSecure == true ) { retcode = AppController_SyncTime ( ) ; } if ( RETCODE_OK == retcode ) { do { retcode = MQTT_ConnectToBroker_Z ( & MqttConnectInfo , MQTT_CONNECT_TIMEOUT_IN_MS , & MqttCredentials ) ; if ( RETCODE_OK != retcode ) { LOG_AT_ERROR ( ( " \r \n " , connectAttemps ) ) ; connectAttemps ++ ; } } while ( RETCODE_OK != retcode && connectAttemps < 10 ) ; connectAttemps = 0UL ; } if ( RETCODE_OK == retcode ) { LOG_AT_INFO ( ( " \r \n " , MqttConnectInfo . BrokerURL , MqttConnectInfo . BrokerPort ) ) ; MQTTOperation_ClientPublish ( ) ; } else { LOG_AT_WARNING ( ( " \r \n " ) ) ; AppController_SetAppStatus ( APP_STATUS_ERROR ) ; vTaskDelay ( pdMS_TO_TICKS ( 30000 ) ) ; BSP_Board_SoftReset ( ) ; } }
@brief Initializes the MQTT Paho Client, set up subscriptions and initializes the timers and tasks
 @return NONE
@brief Initializes the MQTT Paho Client set up subscriptions and initializes the timers and tasks @return NONE
/*Connect to mqtt broker */ //reboot to recover //MQTTOperation_DeInit(); // wait one minute before reboot