From bc2cb7c1ef9e2921cebef3bfbd2df2f26c475774 Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 18 Jul 2017 15:27:43 +0200 Subject: [PATCH 1/9] Update TheThingsNetwork.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently there is no method to check if a node is really still joined to TTN or if the gateway/s in range, is/are still up and running. The "join bit" of "mac get status" response is not reliable... indeed if the only gateway in range is stopped this bit continues to return 1 (joined). Nothing strange since the rule is fire-and-forget. A work around could then use "mac set linkchk nnn". ---------------------------------------- This function sets the time interval for the link check process to be triggered periodically. A of ‘0’ will disable the link check process. When the time interval expires, the next application packet that will be sent to the server will include a link check MAC command. Refer to the LoRaWAN Specification V1.0 document for more information on the link check configuration. ---------------------------------------- Thanks to this command is it possible then get the number of gateway in range and the demodulation margin in dB returned on the last check. --- src/TheThingsNetwork.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TheThingsNetwork.h b/src/TheThingsNetwork.h index 1f4bf29e..6b1dc240 100755 --- a/src/TheThingsNetwork.h +++ b/src/TheThingsNetwork.h @@ -93,6 +93,9 @@ class TheThingsNetwork ttn_response_t poll(port_t port = 1, bool confirm = false); void sleep(uint32_t mseconds); void saveState(); + void linkcheck(uint16_t seconds); + uint8_t linkcheckGateways(); + uint8_t linkcheckMargin(); }; #endif From 4268ff5cdf92ead97600a4236f86289a89fa764d Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 18 Jul 2017 15:31:47 +0200 Subject: [PATCH 2/9] Update TheThingsNetwork.cpp --- src/TheThingsNetwork.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/TheThingsNetwork.cpp b/src/TheThingsNetwork.cpp index 4c0f645b..91ea6890 100755 --- a/src/TheThingsNetwork.cpp +++ b/src/TheThingsNetwork.cpp @@ -190,8 +190,10 @@ const char mac_band[] PROGMEM = "band"; const char mac_ar[] PROGMEM = "ar"; const char mac_rx2[] PROGMEM = "rx2"; const char mac_ch[] PROGMEM = "ch"; +const char mac_gwnb[] PROGMEM = "gwnb"; +const char mac_mrgn[] PROGMEM = "mrgn"; -const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui, mac_nwkskey, mac_appskey, mac_appkey, mac_pwridx, mac_dr, mac_adr, mac_bat, mac_retx, mac_linkchk, mac_rxdelay1, mac_rxdelay2, mac_band, mac_ar, mac_rx2, mac_ch}; +const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui, mac_nwkskey, mac_appskey, mac_appkey, mac_pwridx, mac_dr, mac_adr, mac_bat, mac_retx, mac_linkchk, mac_rxdelay1, mac_rxdelay2, mac_band, mac_ar, mac_rx2, mac_ch, mac_gwnb, mac_mrgn}; #define MAC_DEVADDR 0 #define MAC_DEVEUI 1 @@ -211,6 +213,8 @@ const char *const mac_options[] PROGMEM = {mac_devaddr, mac_deveui, mac_appeui, #define MAC_AR 15 #define MAC_RX2 16 #define MAC_CH 17 +#define MAC_GWNB 18 +#define MAC_MRGN 19 const char mac_join_mode_otaa[] PROGMEM = "otaa"; const char mac_join_mode_abp[] PROGMEM = "abp"; @@ -958,3 +962,33 @@ void TheThingsNetwork::sleep(uint32_t mseconds) modemStream->write(SEND_MSG); debugPrintLn(buffer); } + +void TheThingsNetwork::linkcheck(uint16_t seconds) +{ + clearReadBuffer(); + debugPrint(SENDING); + sendCommand(MAC_TABLE, MAC_PREFIX, true); + sendCommand(MAC_TABLE, MAC_SET, true); + sendCommand(MAC_GET_SET_TABLE, MAC_LINKCHK, true); + + sprintf(buffer, "%u", seconds); + modemStream->write(buffer); + modemStream->write(SEND_MSG); + debugPrintLn(buffer); + return waitForOk(); +} + +uint8_t TheThingsNetwork::linkcheckMargin() +{ + readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_MRGN, buffer, sizeof(buffer)); + + return strtol(buffer, NULL, 10); +} + +uint8_t TheThingsNetwork::linkcheckGateways() +{ + readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_GWNB, buffer, sizeof(buffer)); + + return strtol(buffer, NULL, 10); +} + From e97ce70fb00e344fb38afb7d70e4e974b6835e80 Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 18 Jul 2017 15:32:56 +0200 Subject: [PATCH 3/9] Update TheThingsNetwork.cpp --- src/TheThingsNetwork.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/TheThingsNetwork.cpp b/src/TheThingsNetwork.cpp index 91ea6890..55626684 100755 --- a/src/TheThingsNetwork.cpp +++ b/src/TheThingsNetwork.cpp @@ -978,17 +978,16 @@ void TheThingsNetwork::linkcheck(uint16_t seconds) return waitForOk(); } -uint8_t TheThingsNetwork::linkcheckMargin() +uint8_t TheThingsNetwork::linkcheckGateways() { - readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_MRGN, buffer, sizeof(buffer)); + readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_GWNB, buffer, sizeof(buffer)); return strtol(buffer, NULL, 10); } -uint8_t TheThingsNetwork::linkcheckGateways() +uint8_t TheThingsNetwork::linkcheckMargin() { - readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_GWNB, buffer, sizeof(buffer)); + readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_MRGN, buffer, sizeof(buffer)); return strtol(buffer, NULL, 10); } - From 26eac60989218138d5afba8308c419204cfc76e8 Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 18 Jul 2017 15:49:09 +0200 Subject: [PATCH 4/9] Update TheThingsNetwork.cpp --- src/TheThingsNetwork.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TheThingsNetwork.cpp b/src/TheThingsNetwork.cpp index 55626684..68f43b8b 100755 --- a/src/TheThingsNetwork.cpp +++ b/src/TheThingsNetwork.cpp @@ -975,7 +975,7 @@ void TheThingsNetwork::linkcheck(uint16_t seconds) modemStream->write(buffer); modemStream->write(SEND_MSG); debugPrintLn(buffer); - return waitForOk(); + waitForOk(); } uint8_t TheThingsNetwork::linkcheckGateways() From 879f6b3965b88baee09d018b69df6632a2a4dd48 Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 25 Jul 2017 22:34:01 +0200 Subject: [PATCH 5/9] Update TheThingsNetwork.cpp --- src/TheThingsNetwork.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/TheThingsNetwork.cpp b/src/TheThingsNetwork.cpp index 9a8517f3..66b3c93d 100755 --- a/src/TheThingsNetwork.cpp +++ b/src/TheThingsNetwork.cpp @@ -968,7 +968,7 @@ void TheThingsNetwork::wake() autoBaud(); } -void TheThingsNetwork::linkcheck(uint16_t seconds) +void TheThingsNetwork::linkCheck(uint16_t seconds) { clearReadBuffer(); debugPrint(SENDING); @@ -983,16 +983,14 @@ void TheThingsNetwork::linkcheck(uint16_t seconds) waitForOk(); } -uint8_t TheThingsNetwork::linkcheckGateways() +uint8_t TheThingsNetwork::getLinkCheckGateways() { readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_GWNB, buffer, sizeof(buffer)); - return strtol(buffer, NULL, 10); } -uint8_t TheThingsNetwork::linkcheckMargin() +uint8_t TheThingsNetwork::getLinkCheckMargin() { readResponse(MAC_TABLE, MAC_GET_SET_TABLE, MAC_MRGN, buffer, sizeof(buffer)); - return strtol(buffer, NULL, 10); -} \ No newline at end of file +} From 4fad92b3ee75917385a9c54b866ee8f7935affb0 Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 25 Jul 2017 22:35:02 +0200 Subject: [PATCH 6/9] Update TheThingsNetwork.h --- src/TheThingsNetwork.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TheThingsNetwork.h b/src/TheThingsNetwork.h index 3561f20f..1f950646 100755 --- a/src/TheThingsNetwork.h +++ b/src/TheThingsNetwork.h @@ -94,9 +94,9 @@ class TheThingsNetwork void sleep(uint32_t mseconds); void wake(); void saveState(); - void linkcheck(uint16_t seconds); - uint8_t linkcheckGateways(); - uint8_t linkcheckMargin(); + void linkCheck(uint16_t seconds); + uint8_t getLinkCheckGateways(); + uint8_t getLinkCheckMargin(); }; #endif From 63c8b39e28e21a9f80ee03788900c3efd43798c3 Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 25 Jul 2017 22:42:36 +0200 Subject: [PATCH 7/9] Update TheThingsNetwork.md --- docs/TheThingsNetwork.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/TheThingsNetwork.md b/docs/TheThingsNetwork.md index 5ad9d491..9e6a6cb1 100644 --- a/docs/TheThingsNetwork.md +++ b/docs/TheThingsNetwork.md @@ -175,3 +175,12 @@ void sleep(unsigned long mseconds); ``` - `unsigned long mseconds`: number of milliseconds to sleep. + +## Method: `wake` + +Wake up the LoRa module from sleep before the expiration of the defined time. + +```c +void wake(); +``` + From 5ddd44e666ec33b649bd71a37825c3a1648b3e24 Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 25 Jul 2017 22:49:41 +0200 Subject: [PATCH 8/9] Update TheThingsNetwork.md --- docs/TheThingsNetwork.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/TheThingsNetwork.md b/docs/TheThingsNetwork.md index 9e6a6cb1..016972c7 100644 --- a/docs/TheThingsNetwork.md +++ b/docs/TheThingsNetwork.md @@ -184,3 +184,12 @@ Wake up the LoRa module from sleep before the expiration of the defined time. void wake(); ``` +## Method: `linkCheck` + +Sets the time interval for the link check process to be triggered. + +```c +void linkCheck(uint16_t seconds); +``` + +- `uint16_t seconds`: the time interval in seconds. A value of 0 will disable the link check process. From e03552294f29dfba6b1ef1b11a6c18ad85e25d8b Mon Sep 17 00:00:00 2001 From: alexbn71 Date: Tue, 25 Jul 2017 22:56:36 +0200 Subject: [PATCH 9/9] Update TheThingsNetwork.md --- docs/TheThingsNetwork.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/TheThingsNetwork.md b/docs/TheThingsNetwork.md index 016972c7..b322adbb 100644 --- a/docs/TheThingsNetwork.md +++ b/docs/TheThingsNetwork.md @@ -193,3 +193,19 @@ void linkCheck(uint16_t seconds); ``` - `uint16_t seconds`: the time interval in seconds. A value of 0 will disable the link check process. + +## Method: `getLinkCheckGateways` + +Gets the number of gateways that successfully received the last Link Check Request frame. + +```c +uint8_t getLinkCheckGateways(); +``` + +## Method: `getLinkCheckMargin` + +Gets the demodulation margin as received in the last Link Check Answer frame. + +```c +uint8_t getLinkCheckMargin(); +```