source/MQTTRegistration.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 MQTTRegistration_Init(void* pvParameters) {
	BCDS_UNUSED(pvParameters);
	Retcode_T retcode = RETCODE_OK;
	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(
						("%s: MQTT connection to the broker failed \n\r", MQTTREGISTRATION_LOGPREFIX));
				connectAttemps++;
			}
		} while (RETCODE_OK != retcode && connectAttemps < 10);
		connectAttemps = 0UL;
	}
	if (RETCODE_OK == retcode) {
		retcode = MQTT_SubsribeToTopic_Z(&MqttSubscribeInfo,
		MQTT_SUBSCRIBE_TIMEOUT_IN_MS);
		if (RETCODE_OK != retcode) {
			LOG_AT_ERROR(
					("%s: MQTT subscribe failed \n\r", MQTTREGISTRATION_LOGPREFIX));
		}
	}
	if (RETCODE_OK != retcode) {
		Retcode_RaiseError(retcode);
		vTaskSuspend(NULL);
	}
	LOG_AT_INFO(
			("%s: Successfully connected to [%s:%d]\n\r", MQTTREGISTRATION_LOGPREFIX, MqttConnectInfo.BrokerURL, MqttConnectInfo.BrokerPort));
	int tickRate = (int) pdMS_TO_TICKS(MQTT_REGISTRATION_TICKRATE);
	clientRegistrationTimerHandle = xTimerCreate(
			(const char * const ) "Data Stream", tickRate,
			pdTRUE,
			NULL, MQTTRegistration_PrepareNextRegistrationMsg);
	MQTTRegistration_StartTimer();
	MQTTRegistration_ClientPublish();
}
void MQTTRegistration_Init ( void * pvParameters ) { BCDS_UNUSED ( pvParameters ) ; Retcode_T retcode = RETCODE_OK ; 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 ( ( " \n \r " , MQTTREGISTRATION_LOGPREFIX ) ) ; connectAttemps ++ ; } } while ( RETCODE_OK != retcode && connectAttemps < 10 ) ; connectAttemps = 0UL ; } if ( RETCODE_OK == retcode ) { retcode = MQTT_SubsribeToTopic_Z ( & MqttSubscribeInfo , MQTT_SUBSCRIBE_TIMEOUT_IN_MS ) ; if ( RETCODE_OK != retcode ) { LOG_AT_ERROR ( ( " \n \r " , MQTTREGISTRATION_LOGPREFIX ) ) ; } } if ( RETCODE_OK != retcode ) { Retcode_RaiseError ( retcode ) ; vTaskSuspend ( NULL ) ; } LOG_AT_INFO ( ( " \n \r " , MQTTREGISTRATION_LOGPREFIX , MqttConnectInfo . BrokerURL , MqttConnectInfo . BrokerPort ) ) ; int tickRate = ( int ) pdMS_TO_TICKS ( MQTT_REGISTRATION_TICKRATE ) ; clientRegistrationTimerHandle = xTimerCreate ( ( const char * const ) " " , tickRate , pdTRUE , NULL , MQTTRegistration_PrepareNextRegistrationMsg ) ; MQTTRegistration_StartTimer ( ) ; MQTTRegistration_ClientPublish ( ) ; }
@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 */ /* We raise error and still proceed to publish data periodically */