From 0f28537cc3ea8cc1c57f649910ad134024617e16 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 18 Jul 2022 21:37:42 +0200 Subject: [PATCH] Fix the SF10 size related to MAC Command for US915 preventing communications. Also force setting of the DR after JOIN as this one has been a bit strange on E5 and fix the Join estimate DC duration for US915. --- LoRaComE5.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/LoRaComE5.cpp b/LoRaComE5.cpp index 707341c..a2ef21a 100644 --- a/LoRaComE5.cpp +++ b/LoRaComE5.cpp @@ -565,7 +565,11 @@ bool processTx(void) { } } } - + } else if ( startsWith(loraContext.bufResponse,"+CMSGHEX: Length err") ) { + // current request is not corresponding to the max frame size + // this may be due to a LoRaWan additional content like MAC command + state.cState = EMPTY_DWNLINK; // next time we send a smaller frame + return true; // even if an error, make it as a success. } else { // unprocessed lines } @@ -669,20 +673,29 @@ void do_send(uint8_t port, uint8_t * data, uint8_t sz, uint8_t _dr, uint8_t pwr, // make it simple, the first frame will be lost during join // 1% based on SF and data size (24 Bytes) // @TODO also consider ack - switch (_dr) { - case 7: loraContext.estimatedDCMs = 8200; break; - case 8: loraContext.estimatedDCMs = 14400; break; - case 9: loraContext.estimatedDCMs = 26700; break; - case 10: loraContext.estimatedDCMs = 49400; break; - case 11: loraContext.estimatedDCMs = 106900; break; - case 12: loraContext.estimatedDCMs = 197400; break; - default: - LOGLN(("Invalid SF")); - return; - } + if ( loraConf.zone == ZONE_EU868 ) { + switch (_dr) { + case 7: loraContext.estimatedDCMs = 8200; break; + case 8: loraContext.estimatedDCMs = 14400; break; + case 9: loraContext.estimatedDCMs = 26700; break; + case 10: loraContext.estimatedDCMs = 49400; break; + case 11: loraContext.estimatedDCMs = 106900; break; + case 12: loraContext.estimatedDCMs = 197400; break; + default: + LOGLN(("Invalid SF")); + return; + } + } else { + // No Duty Cycle zones, set a minimum time + loraContext.estimatedDCMs = NONDCZONE_DUTYCYCLE_MS; + } sendATCommand("AT+JOIN","+JOIN: Network joined","+JOIN: Join failed","+JOIN: Done",JOIN_TIMEOUT,true,NULL); loraContext.isJoining = true; state.cState = JOINING; + loraContext.lastDr = -1; // Apparently, after the Join the DR needs to be reset or the frame size becomes too long for US915 (or it is service stuff ?) + loraContext.lastPower = -100; + loraContext.lastRetry = -1; + } else { loraContext.estimatedDCMs = interFrameDutyCycleEstimate(_dr,1);