From 62ecddba6184d93caddb897bc5b3bb3caaa15296 Mon Sep 17 00:00:00 2001 From: Remus Lazar <remus@lazar.info> Date: Sun, 6 Aug 2023 15:29:55 +0200 Subject: [PATCH] Rework the sent ack via mqtt logic Do not send the cmd to mqtt to the sent topic if the siedle client has not increased the tx counter (handle the error case here) --- firmware/lib/SiedleClient/SiedleClient.cpp | 2 +- firmware/src/siedle-service.cpp | 10 +++++++++- firmware/src/siedle-service.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/firmware/lib/SiedleClient/SiedleClient.cpp b/firmware/lib/SiedleClient/SiedleClient.cpp index f3657cc..89b4093 100644 --- a/firmware/lib/SiedleClient/SiedleClient.cpp +++ b/firmware/lib/SiedleClient/SiedleClient.cpp @@ -107,7 +107,7 @@ void SiedleClient::bitTimerISR() { if (bitNumber >= 0) { auto bit = bitRead(cmd_tx_buf, bitNumber--); digitalWrite(outputPin, !bit); - } else { + } else { // bitNumber < 0 digitalWrite(outputPin, LOW); digitalWrite(outputCarrierPin, LOW); diff --git a/firmware/src/siedle-service.cpp b/firmware/src/siedle-service.cpp index c7f6996..8346730 100644 --- a/firmware/src/siedle-service.cpp +++ b/firmware/src/siedle-service.cpp @@ -7,6 +7,7 @@ void SiedleServiceClass::begin() { lastTxMillis = 0; + lastTxCounter = 0; siedleClient = SiedleClient(SIEDLE_A_IN, SIEDLE_TX_PIN, SIEDLE_TX_CARRIER_PIN); siedleClient.begin(); } @@ -40,11 +41,18 @@ void SiedleServiceClass::loop() { if (doSend) { cmd = siedleTxQueue.pop(); siedleClient.sendCmdAsync(cmd); + lastTxCmd = cmd; + } + + // check if we have sent a new cmd since last run and, if so, send the cmd via MQTT + // note: the siedle client will not increment the tx counter if there were errors! + if (siedleClient.txCount > lastTxCounter) { + lastTxCounter = siedleClient.txCount; + MQTTService.sendAsync({RTCSync.getEpoch(), lastTxCmd}, sent); } interrupts(); if (doSend) { - MQTTService.sendAsync({RTCSync.getEpoch(), cmd}, sent); siedleRxTxLog.push({ { RTCSync.getEpoch(), cmd }, tx }); lastTxMillis = now; } diff --git a/firmware/src/siedle-service.h b/firmware/src/siedle-service.h index 84ee7a1..1ca6c1a 100644 --- a/firmware/src/siedle-service.h +++ b/firmware/src/siedle-service.h @@ -46,6 +46,8 @@ class SiedleServiceClass { private: CircularBuffer<siedle_cmd_t, SIEDLE_TX_QUEUE_LEN> siedleTxQueue; unsigned long lastTxMillis; + unsigned int lastTxCounter; + siedle_cmd_t lastTxCmd; }; extern SiedleServiceClass SiedleService;