From b2721c0123ddc24c009afe3c445ce7bb52d48f58 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Wed, 6 Apr 2022 00:03:48 +0200 Subject: [PATCH] reenable error counter and indentation --- mqtt.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/mqtt.c b/mqtt.c index dce7477..10f6642 100644 --- a/mqtt.c +++ b/mqtt.c @@ -35,32 +35,32 @@ void messageArrived(MessageData* md) void mqtt_pub(Client* mqtt_client, char * mqtt_topic, char * mqtt_msg, int mqtt_msg_len) { - //static uint32_t mqtt_pub_count = 0; - //static uint8_t mqtt_err_cnt = 0; - int32_t mqtt_rc; + //static uint32_t mqtt_pub_count = 0; + static uint8_t mqtt_err_cnt = 0; + int32_t mqtt_rc; - //printf(">>MQTT pub msg nr%lu ", ++mqtt_pub_count); - MQTTMessage pubMessage; - pubMessage.qos = QOS0; - pubMessage.id = mes_id++; - pubMessage.payloadlen = (size_t)mqtt_msg_len; - pubMessage.payload = mqtt_msg; - mqtt_rc = MQTTPublish(mqtt_client, mqtt_topic , &pubMessage); - //Analize MQTT publish result (for MQTT failover mode) - if (mqtt_rc == SUCCESSS) - { - //mqtt_err_cnt = 0; - //printf(" - OK\r\n"); - } - else - { - printf("mqtt pub - ERROR\r\n"); - printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n"); - while(1); - //Reboot device after 20 continuous errors (~ 20sec) - //if(mqtt_err_cnt++ > 20) - //{ - // while(1); - //} - } + //printf(">>MQTT pub msg nr%lu ", ++mqtt_pub_count); + MQTTMessage pubMessage; + pubMessage.qos = QOS0; + pubMessage.id = mes_id++; + pubMessage.payloadlen = (size_t)mqtt_msg_len; + pubMessage.payload = mqtt_msg; + mqtt_rc = MQTTPublish(mqtt_client, mqtt_topic , &pubMessage); + //Analize MQTT publish result (for MQTT failover mode) + if (mqtt_rc == SUCCESSS) + { + mqtt_err_cnt = 0; + //printf(" - OK\r\n"); + } + else + { + //while(1); + //Reboot device after 20 continuous errors (~ 20sec) + if(mqtt_err_cnt++ > 10) + { + printf("mqtt pub - ERROR\r\n"); + printf("Connection with MQTT Broker was lost!!\r\nReboot the board..\r\n"); + while(1); + } + } }