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 siedleTxQueue; unsigned long lastTxMillis; + unsigned int lastTxCounter; + siedle_cmd_t lastTxCmd; }; extern SiedleServiceClass SiedleService;