TheThingsNetwork / arduino-device-lib

Arduino Library for TTN Devices
MIT License
207 stars 96 forks source link

Link check command feature #226

Closed alexbn71 closed 6 years ago

alexbn71 commented 6 years ago

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 gateways in range and the demodulation margin in dB returned on the last check.

NB: to not disobey at the TTN Fair Access Policy is in charge of those who use it to make the number of downlink stay within the limits allowed. The max value for "nnn" is 65.535 which corresponds to an interval of 18 hours about.

I've tested this method on my end node and gateway and it seems realiable, see this piece of log:

-- LINK CHECK ENABLED
-- GATEWAYS 1 - MARGIN 16
Sending: mac tx uncnf 1 08011D0000F041250000AC422D0000C242
Successful transmission
Sending: sys sleep 60000
-- LINK CHECK ENABLED
-- GATEWAYS 0 - MARGIN 255
Sending: mac tx uncnf 1 08011D0000F041250000AC422D0000C242
Successful transmission
Sending: sys sleep 60000
-- LINK CHECK ENABLED
-- GATEWAYS 0 - MARGIN 255
Sending: mac tx uncnf 1 08011D0000F041250000AC422D0000C242
Successful transmission
Sending: sys sleep 60000
-- LINK CHECK ENABLED
-- GATEWAYS 0 - MARGIN 255
Sending: mac tx uncnf 1 08011D0000F041250000AC422D0000C242
Successful transmission
Sending: sys sleep 60000
-- LINK CHECK ENABLED
-- GATEWAYS 0 - MARGIN 255
Sending: mac tx uncnf 1 08011D0000F041250000AC422D0000C242
Successful transmission
Sending: sys sleep 60000
-- LINK CHECK ENABLED
-- GATEWAYS 1 - MARGIN 17
Sending: mac tx uncnf 1 08011D0000F041250000AC422D0000C242
Successful transmission
Sending: sys sleep 60000

Explanation: after the classic OTAA the values returned was "-- GATEWAYS 1 - MARGIN 16" then I stopped the "ttn-pkt-fwd" service and it became "-- GATEWAYS 0 - MARGIN 255"... then restarting again "ttn-pkt-fwd" returned to be "GATEWAYS 1 - MARGIN 17".

jpmeijers commented 6 years ago

Seems like a useful feature to me. Can someone in range of multiple gateways perhaps test this feature?

alexbn71 commented 6 years ago

Hi Johan, all done...

johanstokking commented 6 years ago

Released in https://github.com/TheThingsNetwork/arduino-device-lib/releases/tag/v2.5.6