From 9ea4e080ae107ff6e76b81d1bf7c27a6fab725bb Mon Sep 17 00:00:00 2001 From: "christof.strackSAG" Date: Thu, 5 Mar 2020 14:20:23 +0100 Subject: [PATCH] changed postion where mqtt connection is initialized --- source/AppController.c | 36 +++++++++++++++++------------------- source/AppController.h | 15 ++++++++++++++- source/MQTTOperation.c | 28 ++++++++++++++-------------- source/MQTTOperation.h | 2 ++ source/MQTTRegistration.c | 34 +++++++++++++++++----------------- source/MQTTRegistration.h | 2 ++ 6 files changed, 66 insertions(+), 51 deletions(-) diff --git a/source/AppController.c b/source/AppController.c index a520317..68f8853 100644 --- a/source/AppController.c +++ b/source/AppController.c @@ -75,9 +75,9 @@ static void AppController_Enable(void *, uint32_t); static void AppController_Fire(void *); static void AppController_SetClientId(void); static void AppController_StartLEDBlinkTimer(int); -static char clientId[12] = {}; /* global variables ********************************************************* */ +char clientId[14] = {0}; // MAC address 6*2 + \0 'terminating' APP_STATUS app_status; APP_STATUS cmd_status; uint16_t connectAttemps = 0UL; @@ -237,12 +237,23 @@ static void AppController_Enable(void * param1, uint32_t param2) { if (RETCODE_OK == retcode && rc_Boot_Mode == APP_RESULT_OPERATION_MODE) { retcode = Sensor_Enable(); } + + MqttConnectInfo.BrokerURL = MQTTCfgParser_GetMqttBrokerName(); + MqttConnectInfo.BrokerPort = MQTTCfgParser_GetMqttBrokerPort(); + MqttConnectInfo.CleanSession = true; + MqttConnectInfo.KeepAliveInterval = 100; + AppController_SetClientId(); + + LOG_AT_INFO(("AppController_Enable: Device ID for registration in Cumulocity %s.\r\n", + MqttConnectInfo.ClientId)); + if (RETCODE_OK == retcode) { if (pdPASS != xTaskCreate(AppController_Fire, (const char * const ) "AppController", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &AppControllerHandle)) { retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES); } } + if (RETCODE_OK != retcode) { LOG_AT_ERROR(("AppController_Enable: Now calling SoftReset and reboot to recover\r\n")); Retcode_RaiseError(retcode); @@ -270,15 +281,6 @@ static void AppController_Fire(void* pvParameters) { BCDS_UNUSED(pvParameters); - MqttConnectInfo.BrokerURL = MQTTCfgParser_GetMqttBrokerName(); - MqttConnectInfo.BrokerPort = MQTTCfgParser_GetMqttBrokerPort(); - MqttConnectInfo.CleanSession = true; - MqttConnectInfo.KeepAliveInterval = 100; - AppController_SetClientId(); - - LOG_AT_INFO(("AppController_Fire: Device ID for registration in Cumulocity %s\r\n.", - MqttConnectInfo.ClientId)); - if (rc_Boot_Mode == APP_RESULT_OPERATION_MODE) { MqttCredentials.Username = MQTTCfgParser_GetMqttUser(); MqttCredentials.Password = MQTTCfgParser_GetMqttPassword(); @@ -312,42 +314,38 @@ static void AppController_ToogleLEDCallback(xTimerHandle xTimer) { switch(app_status) { case APP_STATUS_STARTED: BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_TOGGLE); - //LOG_AT_TRACE(("STATUS APP_STATUS_STARTED\n")); break; case APP_STATUS_OPERATING_STARTED: BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_OFF); BSP_LED_Switch((uint32_t) BSP_XDK_LED_O, (uint32_t) BSP_LED_COMMAND_TOGGLE); - LOG_AT_TRACE(("STATUS APP_STATUS_RUNNING\n")); break; case APP_STATUS_OPERATING_STOPPED: BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_OFF); BSP_LED_Switch((uint32_t) BSP_XDK_LED_O, (uint32_t) BSP_LED_COMMAND_ON); - LOG_AT_TRACE(("STATUS APP_STATUS_STOPPED\n")); break; case APP_STATUS_ERROR: BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_ON); BSP_LED_Switch((uint32_t) BSP_XDK_LED_O, (uint32_t) BSP_LED_COMMAND_OFF); - LOG_AT_TRACE(("STATUS APP_STATUS_ERROR\n")); break; case APP_STATUS_REBOOT: BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_TOGGLE); BSP_LED_Switch((uint32_t) BSP_XDK_LED_O, (uint32_t) BSP_LED_COMMAND_TOGGLE); - LOG_AT_TRACE(("STATUS APP_STATUS_REBOOT\n")); break; case APP_STATUS_REGISTERED: BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_OFF); BSP_LED_Switch((uint32_t) BSP_XDK_LED_Y, (uint32_t) BSP_LED_COMMAND_ON); - LOG_AT_TRACE(("STATUS APP_STATUS_REGISTERED\n")); break; case APP_STATUS_REGISTERING: BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_OFF); BSP_LED_Switch((uint32_t) BSP_XDK_LED_Y, (uint32_t) BSP_LED_COMMAND_TOGGLE); - LOG_AT_TRACE(("STATUS APP_STATUS_REGISTERING\n")); + break; default: - LOG_AT_WARNING(("AppController: Unknown status\n")); + LOG_AT_WARNING(("AppController: Unknown app status\n")); break; } + LOG_AT_TRACE(("STATUS %s\r\n", app_status_text[app_status])); + switch(cmd_status) { case APP_STATUS_COMMAND_RECEIVED: BSP_LED_Switch((uint32_t) BSP_XDK_LED_R, (uint32_t) BSP_LED_COMMAND_TOGGLE); @@ -361,7 +359,7 @@ static void AppController_ToogleLEDCallback(xTimerHandle xTimer) { // do nothing break; default: - LOG_AT_WARNING(("AppController: Unknown status\n")); + LOG_AT_WARNING(("AppController: Unknown command status\n")); break; } } diff --git a/source/AppController.h b/source/AppController.h index 2aeb658..fcf1b92 100644 --- a/source/AppController.h +++ b/source/AppController.h @@ -219,7 +219,7 @@ typedef enum { } APP_RESULT; typedef enum { - APP_STATUS_ERROR = INT8_C(-2), + APP_STATUS_ERROR = INT8_C(0), APP_STATUS_OPERATING_STARTED = INT8_C(1), APP_STATUS_OPERATING_STOPPED = INT8_C(2), APP_STATUS_STARTED = INT8_C(3), @@ -231,6 +231,19 @@ typedef enum { } APP_STATUS; + +static const char * const app_status_text[] = { + "APP_STATUS_ERROR", + "APP_STATUS_OPERATING_STARTED", + "APP_STATUS_OPERATING_STOPPED", + "APP_STATUS_STARTED", + "APP_STATUS_REBOOT", + "APP_STATUS_REGISTERING", + "APP_STATUS_REGISTERED", + "APP_STATUS_COMMAND_RECEIVED", + "APP_STATUS_COMMAND_CONFIRMED", +}; + typedef enum { APP_ASSET_INITIAL, APP_ASSET_WAITING, diff --git a/source/MQTTOperation.c b/source/MQTTOperation.c index db88b3d..7c6bf2d 100644 --- a/source/MQTTOperation.c +++ b/source/MQTTOperation.c @@ -124,11 +124,11 @@ static void MQTTOperation_ClientReceive(MQTT_SubscribeCBParam_TZ param) { strncpy(appIncomingMsgPayloadBuffer, (const char *) param.Payload, fmin(param.PayloadLength , (sizeof(appIncomingMsgPayloadBuffer) - 1U))); if (strncmp(appIncomingMsgTopicBuffer, TOPIC_DOWNSTREAM_ERROR, strlen(TOPIC_DOWNSTREAM_ERROR)) == 0) { - LOG_AT_ERROR(("MQTTOperation_ClientReceive: Error: %.*s, Error Msg : %.*s\r\n", + LOG_AT_ERROR(("MQTTOperation: Error from upstream: %.*s, Error Msg : %.*s\r\n", (int) param.TopicLength, appIncomingMsgTopicBuffer, (int) param.PayloadLength, appIncomingMsgPayloadBuffer)); } else { - LOG_AT_INFO(("MQTTOperation_ClientReceive: Topic: %.*s, Msg Received: %.*s\r\n", + LOG_AT_INFO(("MQTTOperation: Upstream msg: Topic: %.*s, Msg Received: %.*s\r\n", (int) param.TopicLength, appIncomingMsgTopicBuffer, (int) param.PayloadLength, appIncomingMsgPayloadBuffer)); @@ -136,7 +136,7 @@ static void MQTTOperation_ClientReceive(MQTT_SubscribeCBParam_TZ param) { // split batch of commands in single commands char *token = strtok(appIncomingMsgPayloadBuffer, "\n"); while (token != NULL) { - LOG_AT_ERROR(("MQTTOperation_ClientReceive: Try to place command [%s] in queue!\r\n", token)); + LOG_AT_ERROR(("MQTTOperation: Try to place command [%s] in queue!\r\n", token)); if (xQueueSend(commandQueue,token, 0) != pdTRUE) { LOG_AT_ERROR(("MQTTOperation_ClientReceive: Could not buffer command!\r\n")); break; @@ -155,7 +155,7 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { command = CMD_UNKNOWN; - LOG_AT_INFO(("MQTTOperation_ExecuteCommand: Processing command: [%s]\r\n", commandBuffer)); + LOG_AT_INFO(("MQTTOperation: Execute command: [%s]\r\n", commandBuffer)); // split payload into tokens int token_pos = 0; @@ -229,12 +229,12 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { localbuffer.length = NUMBER_UINT32_ZERO; memset(localbuffer.data, 0x00, SIZE_XXLARGE_BUF); MQTTFlash_FLReadConfig(&localbuffer); - LOG_AT_DEBUG(("MQTTButton: Current configuration in flash:\r\n%s\r\n", localbuffer.data)); + LOG_AT_DEBUG(("MQTTOperation: Current configuration in flash:\r\n%s\r\n", localbuffer.data)); localbuffer.length = NUMBER_UINT32_ZERO; memset(localbuffer.data, 0x00, SIZE_XXLARGE_BUF); MQTTCfgParser_GetConfig(&localbuffer, CFG_FALSE); - LOG_AT_DEBUG(("MQTTButton: Currently used configuration:\r\n%s\r\n", localbuffer.data)); + LOG_AT_DEBUG(("5s: Currently used configuration:\r\n%s\r\n", localbuffer.data)); } else if (strcmp(token, "resetBootstatus") == 0) { commandProgress = DEVICE_OPERATION_IMMEDIATE_BUTTON; command = CMD_COMMAND; @@ -250,11 +250,11 @@ static void MQTTOperation_ExecuteCommand(char * commandBuffer) { command = CMD_CONFIG; } else { commandProgress = DEVICE_OPERATION_BEFORE_FAILED; - LOG_AT_WARNING(("MQTTOperation: Unknown command: %s\r\n", token)); + LOG_AT_WARNING(("5s: Unknown command: %s\r\n", token)); } LOG_AT_DEBUG(("MQTTOperation: Token: [%s] recognized as command: [%i]\r\n", token, command)); } else if (command == CMD_FIRMWARE){ - LOG_AT_DEBUG(("MQTTOperation: Phase parse command firmware name: token_pos: [%i]\r\n", token_pos)); + LOG_AT_DEBUG(("MQTTOperation: Phase parse command firmware name: token_pos: [%i]\r\n",token_pos)); MQTTCfgParser_SetFirmwareName(token); } else if (command == CMD_MESSAGE) { BSP_LED_Switch((uint32_t) BSP_XDK_LED_Y, (uint32_t) BSP_LED_COMMAND_TOGGLE); @@ -372,7 +372,7 @@ static void MQTTOperation_RestartCallback(xTimerHandle xTimer) { */ static void MQTTOperation_ClientPublish(void) { - LOG_AT_INFO(("MQTTOperation_ClientPublish: Start publishing ...\r\n")); + LOG_AT_INFO(("MQTTOperation: Start publishing ...\r\n")); semaphoreAssetBuffer = xSemaphoreCreateBinary(); xSemaphoreGive(semaphoreAssetBuffer); @@ -657,7 +657,7 @@ static void MQTTOperation_AssetUpdate(xTimerHandle xTimer) { static uint32_t keepAlive = 0; static uint32_t mvoltage = 0, battery = 0; - LOG_AT_TRACE(("MQTTOperation: Starting buffering device data ...\r\n")); + //LOG_AT_TRACE(("MQTTOperation: Starting buffering device data ...\r\n")); // take semaphore to avoid publish thread to access the buffer BaseType_t semaphoreResult = xSemaphoreTake(semaphoreAssetBuffer, pdMS_TO_TICKS(SEMAPHORE_TIMEOUT_NULL)); @@ -813,7 +813,7 @@ static void MQTTOperation_AssetUpdate(xTimerHandle xTimer) { TimeStamp_SecsToTm(sntpTimeStamp, &time); TimeStamp_TmToIso8601(&time, timezoneISO8601format, 40); - LOG_AT_TRACE(("MQTTOperation_SensorUpdate: current time: %s\r\n", timezoneISO8601format)); + LOG_AT_TRACE(("MQTTOperation: current time: %s\r\n", timezoneISO8601format)); assetStreamBuffer.length += snprintf( assetStreamBuffer.data + assetStreamBuffer.length, sizeof (assetStreamBuffer.data) - assetStreamBuffer.length, @@ -835,7 +835,7 @@ static void MQTTOperation_AssetUpdate(xTimerHandle xTimer) { // release semaphore and let publish thread access the buffer xSemaphoreGive(semaphoreAssetBuffer); - LOG_AT_TRACE(("MQTTOperation: Finished buffering device data\r\n")); + //LOG_AT_TRACE(("MQTTOperation: Finished buffering device data\r\n")); } static void MQTTOperation_SensorUpdate(xTimerHandle xTimer) { @@ -959,7 +959,7 @@ static float MQTTOperation_CalcSoundPressure(float acousticRawValue){ void MQTTOperation_QueueCommand(void * param1, uint32_t param2) { BCDS_UNUSED(param2); if (xQueueSend(commandQueue,(char *) param1, 0) != pdTRUE) { - LOG_AT_ERROR(("MQTTOperation_QueueCommand: Could not buffer command!\r\n")); + LOG_AT_ERROR(("MQTTOperation: Could not buffer command!\r\n")); } return; } @@ -979,7 +979,7 @@ void MQTTOperation_Init(void) { // ckeck if reboot process is pending to be confirmed char readbuffer[SIZE_SMALL_BUF]; /* Temporary buffer for write file */ MQTTFlash_FLReadBootStatus((uint8_t *) readbuffer); - LOG_AT_DEBUG(("MQTTOperation_Init: Reading boot status: [%s]\r\n", readbuffer)); + LOG_AT_DEBUG(("MQTTOperation: Reading boot status: [%s]\r\n", readbuffer)); if ((strncmp(readbuffer, BOOT_PENDING, strlen(BOOT_PENDING)) == 0)) { command = CMD_RESTART; diff --git a/source/MQTTOperation.h b/source/MQTTOperation.h index a4affc4..786fa86 100644 --- a/source/MQTTOperation.h +++ b/source/MQTTOperation.h @@ -43,6 +43,8 @@ #define MILLISECONDS(x) ((portTickType) x / portTICK_RATE_MS) #define SECONDS(x) ((portTickType) (x * 1000) / portTICK_RATE_MS) +#define MQTTOPERATION_LOGPREFIX "MQTTOperation" + /* global function prototype declarations */ void MQTTOperation_Init(void); diff --git a/source/MQTTRegistration.c b/source/MQTTRegistration.c index 928ba57..7ea28c4 100644 --- a/source/MQTTRegistration.c +++ b/source/MQTTRegistration.c @@ -72,7 +72,7 @@ static MQTT_Publish_TZ MqttPublishInfo = { .Topic = TOPIC_REGISTRATION, .QoS = static void MQTTRegistration_PrepareNextRegistrationMsg (xTimerHandle xTimer){ (void) xTimer; - LOG_AT_DEBUG(("MQTTRegistration: requesting credentials ...\n\r")); + LOG_AT_DEBUG(("%s: requesting credentials ...\n\r", MQTTREGISTRATION_LOGPREFIX)); // send empty message to Cumulocity to trigger acceptance of the regitration in WebUI assetStreamBuffer.length += snprintf(assetStreamBuffer.data + assetStreamBuffer.length, sizeof (assetStreamBuffer.data) - assetStreamBuffer.length, " \n"); } @@ -95,7 +95,7 @@ static void MQTTRegistration_ClientReceive(MQTT_SubscribeCBParam_TZ param) { strncpy(appIncomingMsgTopicBuffer, (const char *) param.Topic, fmin(param.TopicLength, (sizeof(appIncomingMsgTopicBuffer) - 1U))); strncpy(appIncomingMsgPayloadBuffer, (const char *) param.Payload, fmin(param.PayloadLength , (sizeof(appIncomingMsgPayloadBuffer) - 1U))); - LOG_AT_DEBUG(("MQTTRegistration: Received new message on topic: %s from upstream: [%s]\n\r", + LOG_AT_DEBUG(("%s: Received new message on topic: %s from upstream: [%s]\n\r", MQTTREGISTRATION_LOGPREFIX, appIncomingMsgTopicBuffer, appIncomingMsgPayloadBuffer)); if ((strncmp(param.Topic, TOPIC_CREDENTIAL, param.TopicLength) == 0)) { AppController_SetStatus(APP_STATUS_REGISTERED); @@ -109,24 +109,24 @@ static void MQTTRegistration_ClientReceive(MQTT_SubscribeCBParam_TZ param) { int command_pos = 0; //mark positon for command which is parsed char *token = strtok(appIncomingMsgPayloadBuffer, ","); while (token != NULL) { - LOG_AT_TRACE(("MQTTRegistration: Parsed token: [%s], command_pos: %i token_pos: %i \n\r", + LOG_AT_TRACE(("%s: Parsed token: [%s], command_pos: %i token_pos: %i \n\r", MQTTREGISTRATION_LOGPREFIX, token, command_pos, token_pos)); if (token_pos == 0 && strcmp(token, TEMPLATE_STD_CREDENTIALS) == 0) { - LOG_AT_TRACE(("MQTTRegistration: Correct message type \n\r")); + LOG_AT_TRACE(("%s: Correct message type \n\r", MQTTREGISTRATION_LOGPREFIX)); command_pos = 1; // mark that we are in a credential notification message } else if (command_pos == 1 && token_pos == 1) { // found tenant snprintf(tenant,SIZE_XSMALL_BUF,token); - LOG_AT_TRACE(("MQTTRegistration: Found tenant: [%s]\n\r", token)); + LOG_AT_TRACE(("%s: Found tenant: [%s]\n\r", MQTTREGISTRATION_LOGPREFIX, token)); } else if (command_pos == 1 && token_pos == 2) { // found username snprintf(username, SIZE_XSMALL_BUF,"%s/%s", tenant, token); - LOG_AT_TRACE(("MQTTRegistration: Found username: [%s], [%s]\n\r", token, username)); + LOG_AT_TRACE(("%s: Found username: [%s], [%s]\n\r", MQTTREGISTRATION_LOGPREFIX, token, username)); } else if (command_pos == 1 && token_pos == 3) { snprintf(password, SIZE_XSMALL_BUF, token); - LOG_AT_TRACE(("MQTTRegistration: Found password: [%s]\n\r", token)); + LOG_AT_TRACE(("%s: Found password: [%s]\n\r", MQTTREGISTRATION_LOGPREFIX, token)); } else { - LOG_AT_TRACE(("MQTTRegistration: Wrong message format\n\r")); + LOG_AT_TRACE(("%s: Wrong message format\n\r", MQTTREGISTRATION_LOGPREFIX)); assert(0); } token = strtok(NULL, ", "); @@ -172,7 +172,7 @@ static void MQTTRegistration_RestartCallback(xTimerHandle xTimer) { */ static void MQTTRegistration_ClientPublish(void) { - LOG_AT_DEBUG(("MQTTRegistration: MQTTRegistration_ClientPublish starting \n\r")); + LOG_AT_DEBUG(("%s: MQTTRegistration_ClientPublish starting \n\r", MQTTREGISTRATION_LOGPREFIX)); Retcode_T retcode = RETCODE_OK; while (1) { /* Check whether the WLAN network connection is available */ @@ -187,7 +187,7 @@ static void MQTTRegistration_ClientPublish(void) { retcode = MQTT_PublishToTopic_Z(&MqttPublishInfo, MQTT_PUBLISH_TIMEOUT_IN_MS); if (RETCODE_OK != retcode) { - LOG_AT_ERROR(("MQTTRegistration: MQTT publish failed \n\r")); + LOG_AT_ERROR(("%s: MQTT publish failed \n\r", MQTTREGISTRATION_LOGPREFIX)); Retcode_RaiseError(retcode); } } @@ -213,7 +213,7 @@ void MQTTRegistration_StartTimer(void){ memset(assetStreamBuffer.data, 0x00, SIZE_SMALL_BUF); assetStreamBuffer.length = NUMBER_UINT32_ZERO; /* Start the timers */ - LOG_AT_TRACE(("MQTTRegistration: Start publishing ...\n\r")); + LOG_AT_TRACE(("%s: Start publishing ...\n\r", MQTTREGISTRATION_LOGPREFIX)); xTimerStart(clientRegistrationTimerHandle, UINT32_MAX); AppController_SetStatus(APP_STATUS_REGISTERING); return; @@ -239,7 +239,7 @@ void MQTTRegistration_Init(void) { MQTT_CONNECT_TIMEOUT_IN_MS, &MqttCredentials); if (RETCODE_OK != retcode) { LOG_AT_ERROR( - ("MQTTRegistration: MQTT connection to the broker failed \n\r")); + ("%s: MQTT connection to the broker failed \n\r", MQTTREGISTRATION_LOGPREFIX)); connectAttemps++; } } while (RETCODE_OK != retcode && connectAttemps < 10); @@ -251,7 +251,7 @@ void MQTTRegistration_Init(void) { retcode = MQTT_SubsribeToTopic_Z(&MqttSubscribeInfo, MQTT_SUBSCRIBE_TIMEOUT_IN_MS); if (RETCODE_OK != retcode) { - LOG_AT_ERROR(("MQTTRegistration: MQTT subscribe failed \n\r")); + LOG_AT_ERROR(("%s: MQTT subscribe failed \n\r", MQTTREGISTRATION_LOGPREFIX)); } } @@ -261,7 +261,7 @@ void MQTTRegistration_Init(void) { vTaskSuspend(NULL); } - LOG_AT_INFO(("MQTTRegistration: Successfully connected to [%s:%d]\n\r", + 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); @@ -282,7 +282,7 @@ void MQTTRegistration_Init(void) { */ void MQTTRegistration_DeInit(void) { - LOG_AT_INFO(("MQTTRegistration: Calling DeInit\n\r")); + LOG_AT_INFO(("%s: Calling DeInit\n\r", MQTTREGISTRATION_LOGPREFIX)); MQTT_UnSubsribeFromTopic_Z(&MqttSubscribeInfo, MQTT_SUBSCRIBE_TIMEOUT_IN_MS); Mqtt_DisconnectFromBroker_Z(); @@ -340,7 +340,7 @@ static Retcode_T MQTTRegistration_ValidateWLANConnectivity(void) { } if (RETCODE_OK != retcode) { - LOG_AT_ERROR(("MQTTRegistration: MQTT connection to the broker failed, try again : [%hu] ... \r\n", connectAttemps )); + LOG_AT_ERROR(("%s: MQTT connection to the broker failed, try again : [%hu] ... \r\n", MQTTREGISTRATION_LOGPREFIX, connectAttemps )); vTaskDelay(pdMS_TO_TICKS(3000)); } else { //reset connection counter @@ -350,7 +350,7 @@ static Retcode_T MQTTRegistration_ValidateWLANConnectivity(void) { // test if we have to reboot if (connectAttemps > 10) { - LOG_AT_WARNING(("MQTTOperation: Now calling SoftReset to recover\r\n")); + LOG_AT_WARNING(("%s: Now calling SoftReset to recover\r\n", MQTTREGISTRATION_LOGPREFIX)); // wait one minute before reboot vTaskDelay(pdMS_TO_TICKS(30000)); BSP_Board_SoftReset(); diff --git a/source/MQTTRegistration.h b/source/MQTTRegistration.h index bc4c216..534ef70 100644 --- a/source/MQTTRegistration.h +++ b/source/MQTTRegistration.h @@ -31,6 +31,8 @@ #define MILLISECONDS(x) ((portTickType) x / portTICK_RATE_MS) #define SECONDS(x) ((portTickType) (x * 1000) / portTICK_RATE_MS) +#define MQTTREGISTRATION_LOGPREFIX "MQTTRegistration" + /* global function prototype declarations */ void MQTTRegistration_Init(void); void MQTTRegistration_DeInit(void);