From 9926c12f529b0ba52e12e9f83897f739df8d0072 Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Sat, 13 Apr 2019 12:58:31 +0200 Subject: [PATCH] correct isue with using a different receiver with RFM69 than the default and ack issue #376 #375 --- ZgatewayRFM69.ino | 62 +++++++++++------------------------------------ 1 file changed, 14 insertions(+), 48 deletions(-) diff --git a/ZgatewayRFM69.ino b/ZgatewayRFM69.ino index 1d6cd07..e1efb8e 100644 --- a/ZgatewayRFM69.ino +++ b/ZgatewayRFM69.ino @@ -181,13 +181,8 @@ boolean RFM69toMQTT(void) { #ifdef simpleReceiving void MQTTtoRFM69(char * topicOri, char * datacallback) { - int loops; - uint32_t startMillis; - static uint32_t deltaMillis = 0; - - String topic = topicOri; - - if (topic == subjectMQTTtoRFM69) { + + if(strstr(topicOri, subjectMQTTtoRFM69) != NULL){ trc(F("MQTTtoRFM69 data analysis")); char data[RF69_MAX_DATA_LEN+1]; memcpy(data, (void *)datacallback, RF69_MAX_DATA_LEN); @@ -203,26 +198,13 @@ boolean RFM69toMQTT(void) { trc(F("RFM69 receiver ID:")); trc(valueRCV); } - loops = 10; - startMillis = millis(); - while (loops--) { - if(radio.sendWithRetry(valueRCV, data, strlen(data))) { - deltaMillis = millis() - startMillis; - trc(F(" OK ")); - trc(deltaMillis); - - // Acknowledgement to the GTWRF topic - char buff[sizeof(subjectGTWRFM69toMQTT)+4]; - sprintf(buff, "%s/%d", subjectGTWRFM69toMQTT, radio.SENDERID); - pub(buff, data); - } - else { - trc(F("!")); - } - delay(50); - } - if (loops <= 0) { - deltaMillis = 0; + if(radio.sendWithRetry(valueRCV, data, strlen(data)),10) { + trc(F(" OK ")); + // Acknowledgement to the GTWRF topic + char buff[sizeof(subjectGTWRFM69toMQTT)+4]; + sprintf(buff, "%s/%d", subjectGTWRFM69toMQTT, radio.SENDERID); + pub(buff, data); + } else { trc(F("RFM69 sending failed")); } } @@ -236,30 +218,14 @@ boolean RFM69toMQTT(void) { trc(F("MQTTtoRFM69 json data analysis")); if(data){ trc(F("MQTTtoRFM69 data ok")); - int loops; - uint32_t startMillis; - static uint32_t deltaMillis = 0; int valueRCV = RFM69data["receiverid"]| defaultRFM69ReceiverId; //default receiver id value trc(F("RFM69 receiver ID:")); trc(valueRCV); - - loops = 10; - startMillis = millis(); - while (loops--) { - if(radio.sendWithRetry(valueRCV, data, strlen(data))) { - deltaMillis = millis() - startMillis; - trc(F(" OK ")); - trc(deltaMillis); - // Acknowledgement to the GTWRF topic - pub(subjectGTWRFM69toMQTT, RFM69data);// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also - } - else { - trc(F("!")); - } - delay(50); - } - if (loops <= 0) { - deltaMillis = 0; + if(radio.sendWithRetry(valueRCV, data, strlen(data)),10) { + trc(F(" OK ")); + // Acknowledgement to the GTWRF topic + pub(subjectGTWRFM69toMQTT, RFM69data);// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also + } else { trc(F("MQTTtoRFM69 sending failed")); } }else{