From 82a046ff5ef431ee0c57da9a219ab7d698977f60 Mon Sep 17 00:00:00 2001 From: Strack Date: Tue, 28 Jul 2020 15:48:26 +0100 Subject: [PATCH] send error msgs as events to c8y --- source/MQTTOperation.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/source/MQTTOperation.c b/source/MQTTOperation.c index b1e2304..66e16ae 100644 --- a/source/MQTTOperation.c +++ b/source/MQTTOperation.c @@ -132,6 +132,12 @@ static void MQTTOperation_ClientReceive(MQTT_SubscribeCBParam_TZ param) { strlen(TOPIC_DOWNSTREAM_ERROR)) == 0) { LOG_AT_ERROR( ("MQTTOperation: Error from upstream: %.*s, Error Msg : %.*s\r\n", (int) param.TopicLength, appIncomingMsgTopicBuffer, (int) param.PayloadLength, appIncomingMsgPayloadBuffer)); + assetStreamBuffer.length += + snprintf(assetStreamBuffer.data + assetStreamBuffer.length, + sizeof(assetStreamBuffer.data) + - assetStreamBuffer.length, + "400,xdk_ErrorCountEvent,\"Error Msg : %.*s\"\r\n", + (int) param.PayloadLength, appIncomingMsgPayloadBuffer); } else { LOG_AT_INFO( ("MQTTOperation: Upstream msg: Topic: %.*s, Msg Received: %.*s\r\n", (int) param.TopicLength, appIncomingMsgTopicBuffer, (int) param.PayloadLength, appIncomingMsgPayloadBuffer)); @@ -894,12 +900,14 @@ static void MQTTOperation_AssetUpdate(xTimerHandle xTimer) { LOG_AT_TRACE(("MQTTOperation: current time: %s\r\n", timezoneISO8601format)); - assetStreamBuffer.length += - snprintf(assetStreamBuffer.data + assetStreamBuffer.length, - sizeof(assetStreamBuffer.data) - - assetStreamBuffer.length, - "400,xdk_ErrorCountEvent,\"Errors: Collision Semaphore/Error Publish:%i/%i!\"\r\n", - errorCountSemaphore, errorCountPublish); + // only send event when some error occurs + if (errorCountSemaphore != 0 || errorCountPublish != 0 ) + assetStreamBuffer.length += + snprintf(assetStreamBuffer.data + assetStreamBuffer.length, + sizeof(assetStreamBuffer.data) + - assetStreamBuffer.length, + "400,xdk_ErrorCountEvent,\"Errors: Collision Semaphore/Error Publish:%i/%i!\"\r\n", + errorCountSemaphore, errorCountPublish); #if INCLUDE_uxTaskGetStackHighWaterMark uint32_t everFreeHeap = xPortGetMinimumEverFreeHeapSize();