# TTN Node - link check does not work?

**URL:** <https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981>\
**Category:** Hardware\
**Created:** [November 21, 2018, 1:48pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981 "2018-11-21T13:48:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![strangerFlo](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@strangerFlo](https://www.thethingsnetwork.org/forum/u/strangerFlo)\
**Post date:** [November 21, 2018, 1:48pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/1 "2018-11-21T13:48:13Z")

</div>

Hello,

I have tried to setup a link check on my TTN node using the [TTN Arduino API functions](https://www.thethingsnetwork.org/docs/devices/arduino/api/network.html#method-linkcheck). I want to send a link check request to the network server, receive the link check answer on the node and the send the info back to my application.

Please see the relevant code below:

```
    void setup()
    {
      loraSerial.begin(57600);
      debugSerial.begin(9600);

      // Wait a maximum of 10s for Serial Monitor
  while (!debugSerial && millis() < 10000)
    ;

  // Config Node
  node = TheThingsNode::setup();
  node->configLight(true);
  node->configInterval(true, 60000);
  node->configTemperature(true);
  node->onWake(wake);
  node->onInterval(interval);
  node->onSleep(sleep);
  node->onMotionStart(onMotionStart);
  node->onButtonRelease(onButtonRelease);

  //Set the time interval for the link check process to be triggered:
  uint16_t interval = 30;
  ttn.linkCheck(interval); //time interval in seconds. 0 will disable the link check process.
...
}

void sendData(uint8_t port)
{
...
  byte *bytes;
  byte payload[11];
...
  //link test
  uint8_t demod_margin = ttn.getLinkCheckMargin(); //Gets the demodulation margin as received in the last Link Check Answer frame.
  bytes = (byte *)&demod_margin;
  payload[6] = bytes[0];
  debugSerial.print("demodulation margin: %u", demod_margin);
  uint8_t num_gateways = ttn.getLinkCheckGateways(); //Gets the number of gateways that successfully received the last Link Check Request frame.
  bytes = (byte *)&num_gateways;
  payload[7] = bytes[1];
  payload[8] = bytes[0];
...
  ttn.sendBytes(payload, sizeof(payload), port);
}

```

The upload to the node with Arduino IDE works fine and I receive the uplinks with the fields, but num\_gateways is always 0 and demod\_margin is always 255 (reserved value!). I also can’t see any of the uplinks containing the the LinkCheckReq command and no (empty) payload. I have used to TTN node with both, the official TTN servers and a local installation of Brocaar.

Do you have any idea what my mistake is? Is there an example that I could compare my code to?

Thank you for your help!

Kind regards,

Flo

---

<div class="post-metadata">

**Author:** ![BoRRoZ](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/borroz/32/44234_2.png) [@BoRRoZ](https://www.thethingsnetwork.org/forum/u/BoRRoZ)\
**Post date:** [November 21, 2018, 2:07pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/2 "2018-11-21T14:07:06Z")

</div>

as far as I know it will be implemented in V3

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [November 21, 2018, 6:49pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/3 "2018-11-21T18:49:28Z")

</div>

This should be supported in V2 too, and should work in the Arduino library since July 2017, given [the example log (and its explanation) in the pull request](https://github.com/TheThingsNetwork/arduino-device-lib/pull/226) that added the feature.

> [@strangerFlo](#):
>
> I also can’t see any of the uplinks containing the the LinkCheckReq command and no (empty) payload. I have used to TTN node with both, the official TTN servers and a local installation of Brocaar.

If you’re really not seeing the request going out, then I’d say it doesn’t even matter which backend you’re using. But why are you expecting an empty payload? The `linkCheck` command is delegated to the RN2483 module by using `mac set linkchk`, which [is documented as](http://ww1.microchip.com/downloads/en/DeviceDoc/40001784C.pdf#page=29):

> When the time interval expires, the next application packet that will be sent to the server will include also a link check MAC command.

So, I feel it will not be sending standalone packets just for the link check. So, are you sure one of the regular uplinks does not include the MAC command?

If you actually do see the MAC command: are you sure you can receive downlinks? (Like: are you using OTAA?) And anything in the gateway’s Traffic page in TTN Console?

---

<div class="post-metadata">

**Author:** ![strangerFlo](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@strangerFlo](https://www.thethingsnetwork.org/forum/u/strangerFlo)\
**Post date:** [November 23, 2018, 10:45am UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/4 "2018-11-23T10:45:23Z")

</div>

Thank you for your quick response!

First of all, the zero-payload of the uplink was nonsense of course. I referred to the LoRaWANv1.1 spec where it reads:

> With the LinkCheckReq command, an end-device may validate its connectivity with the  
> network. The **command** has **no payload**.

The command has no payload, but not the whole message. I should read more carefully.

> So, are you sure one of the regular uplinks does not include the MAC command?

No, now I am actually not sure.

> are you sure you can receive downlinks? (Like: are you using OTAA?)

I use OTAA (with Brocaar right now). I get uplinks, but no downlinks. Do I need to schedule downlinks by myself with an application or will the network server respond by itself with a downlink just containing the LinkCheckAns command?  
Now, I am using TTN again and I also scheduled some downlinks (with nonsense-payload) to carry the LinkCheckAns piggy-back, but the following uplinks do not contain valid values for demod\_margin and num\_gateways.

 ![link%20test%20downlink](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/a/d/adffd15b956ad2b06bc8b2fe6f1630750e600c0e.png)

The LoRaWANv1.1 spec just says:

> When a LinkCheckReq is received by the Network Server via one or multiple gateways, it  
> responds with a LinkCheckAns command.

???

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [November 23, 2018, 10:58am UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/5 "2018-11-23T10:58:09Z")

</div>

> [@strangerFlo](#):
>
> I use OTAA (with Brocaar right now). I get uplinks, but no downlinks.

If OTAA works, then you _do_ get downlinks, as the OTAA Join Accept is a downlink too. So, you’re sure downlinks work. Also, for LinkCheckAns you do not need to schedule a downlink yourself, I think.

To make sure your uplinks include the LinkCheckReq command, paste a raw packet from the gateway into [an online decoder](https://runkit.io/avbentem/lorawan-packet-decoder/branches/master) and then show us the values for `FCtrl` and `FOpts` (or show us a full packet here). While testing, make sure to use a very small value (I’d say: 1 second) in `ttn.linkCheck`, to increase the chances that a LinkCheckReq is requested.

Also, I’ve no idea if the Brocaar version supports it. TTN should.

---

<div class="post-metadata">

**Author:** ![kersing](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/kersing/32/44777_2.png) [@kersing](https://www.thethingsnetwork.org/forum/u/kersing)\
**Post date:** [November 23, 2018, 11:19am UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/6 "2018-11-23T11:19:02Z")

</div>

> [@strangerFlo](#):
>
> LoRaWANv1.1 spec

You are aware TTN has not implemented v1.1? (Yet)

---

<div class="post-metadata">

**Author:** ![strangerFlo](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@strangerFlo](https://www.thethingsnetwork.org/forum/u/strangerFlo)\
**Post date:** [November 23, 2018, 11:25am UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/7 "2018-11-23T11:25:46Z")

</div>

For TTN I get something like this:

```
Assuming hex-encoded packet
1240001C09E3FF000CDE

Message Type = Join Request
  PHYPayload = 1240001C09E3FF000CDE

( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
        MHDR = 12
  MACPayload = 40001C09E3
         MIC = FF000CDE (from packet) INVALID (tried MSB 0000-FFFF)
             = AF291AA5 (expected, assuming 32 bits frame counter with MSB 0000)

( MACPayload = AppEUI[8] | DevEUI[8] | DevNonce[2] )
      AppEUI = 0C00FFE3091C0040
      DevEUI = DE
    DevNonce = 

```

With Brocaar, I get the following  
[uplinks brocaar.txt](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/9/a/9ac35d918fddc88fc2b116ea7701bec7c4987860.txt) (5.8 KB)

FOpts is always null. ☹

> You are aware TTN has not implemented v1.1? (Yet)

No, I wasn’t. Nevertheless, the link check should still work, I guess. Brocaar will negotiate the max. supported minor version of LoRaWAN with the TTN node during the OTAA anyway.

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [November 23, 2018, 11:47am UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/8 "2018-11-23T11:47:37Z")

</div>

You’re showing the Join Request. Instead, you’ll want to look at the uplinks _after_ the device has joined.

---

<div class="post-metadata">

**Author:** ![strangerFlo](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@strangerFlo](https://www.thethingsnetwork.org/forum/u/strangerFlo)\
**Post date:** [November 23, 2018, 12:06pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/9 "2018-11-23T12:06:05Z")

</div>

I did look at a normal uplink. I don’t know why it tells me it is a join request.

Another trial way after successful join:  
 ![Screenshot%20from%202018-11-23%2013-03-56](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/0/a/0a0295e58ed75a00af04dfa0da554cddd431a46d.png)

```
Assuming hex-encoded packet
1240002509B8FF000CDE

Message Type = Join Request
  PHYPayload = 1240002509B8FF000CDE

( PHYPayload = MHDR[1] | MACPayload[..] | MIC[4] )
        MHDR = 12
  MACPayload = 40002509B8
         MIC = FF000CDE (from packet) INVALID (tried MSB 0000-FFFF)
             = 3DEF4FEF (expected, assuming 32 bits frame counter with MSB 0000)

( MACPayload = AppEUI[8] | DevEUI[8] | DevNonce[2] )
      AppEUI = 0C00FFB809250040
      DevEUI = DE
    DevNonce =
```

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [November 23, 2018, 12:09pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/10 "2018-11-23T12:09:02Z")

</div>

Ah, you’re pasting the application payload into that decoder. You should use the full LoRaWAN packet from the gateway. (Like from the gateway’s Traffic page in TTN Console.)

---

<div class="post-metadata">

**Author:** ![strangerFlo](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@strangerFlo](https://www.thethingsnetwork.org/forum/u/strangerFlo)\
**Post date:** [November 23, 2018, 12:32pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/11 "2018-11-23T12:32:52Z")

</div>

🤦‍♂️  
[actual\_packets\_decoded.txt](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/3/7/3713894e2d41bc936a442734ba607c0543ca0e43.txt) (2.8 KB)

There you go. Recorded with TTN. Still, no FOpts.

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [November 23, 2018, 12:44pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/12 "2018-11-23T12:44:56Z")

</div>

Indeed, so no LinkCheckReq. ☹

Did you minimize the time in `ttn.linkCheck(1)`?

(Note that you’re missing some values of the frame counter; jumping from 37, 39 to 47, but maybe you received all?)

---

<div class="post-metadata">

**Author:** ![strangerFlo](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@strangerFlo](https://www.thethingsnetwork.org/forum/u/strangerFlo)\
**Post date:** [November 23, 2018, 1:04pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/13 "2018-11-23T13:04:32Z")

</div>

```
 uint16_t interval = 1;
  ttn.linkCheck(interval);

```

He had his chance. 😁

I did some random selection of frames. I received all frames of course.

---

<div class="post-metadata">

**Author:** ![BoRRoZ](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/borroz/32/44234_2.png) [@BoRRoZ](https://www.thethingsnetwork.org/forum/u/BoRRoZ)\
**Post date:** [November 23, 2018, 1:08pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/14 "2018-11-23T13:08:38Z")

</div>

isn’t a linkcheck a kind of downlink message /ack and will there be _fair use_ limitations ? @htdvisser

---

<div class="post-metadata">

**Author:** ![strangerFlo](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@strangerFlo](https://www.thethingsnetwork.org/forum/u/strangerFlo)\
**Post date:** [November 23, 2018, 1:58pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/15 "2018-11-23T13:58:28Z")

</div>

I don’t know about any.

---

<div class="post-metadata">

**Author:** ![htdvisser](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/htdvisser/32/45312_2.png) [@htdvisser](https://www.thethingsnetwork.org/forum/u/htdvisser)\
**Post date:** [November 23, 2018, 2:47pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/16 "2018-11-23T14:47:49Z")

</div>

Nothing changed since 2016 ([Questions regarding the TTN fair access policy - #4 by htdvisser](https://www.thethingsnetwork.org/forum/t/questions-regarding-the-ttn-fair-access-policy/2848/4)):

> Everything counts. Each uplink counts towards the total uplink, and each downlink (including ACKs) counts towards the total downlink.

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [November 23, 2018, 5:11pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/17 "2018-11-23T17:11:06Z")

</div>

Like Hylke confirmed it is subject to the Fair Access Policy. But as that is not enforced yet, your tests should not be affected by that. (Also, so far I think the problem is that the device is not even asking for the link check.)

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [November 23, 2018, 7:38pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/18 "2018-11-23T19:38:37Z")

</div>

Ah, finally unpacked my The Things Node to test it myself 😉

It seems you need to call `ttn.linkCheck(interval)` after you’ve joined. So, this works for me:

```cpp
ttn.join(appEui, appKey);

// Set the time interval in seconds for the link check process to be triggered;
// 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 also a
// link check MAC command in the LoRaWAN FOpts field.
uint16_t interval = 1;
ttn.linkCheck(interval); 

```

Of course, `interval = 1` is just for testing.

This yields, e.g., [40DA22012601080002020A3B48DAB7EFC8B9A7461D249E](http://runkit.io/avbentem/lorawan-packet-decoder/branches/master?data=40DA22012601080002020A3B48DAB7EFC8B9A7461D249E&nwkskey=95C823FBA73BBFD98DA82C2539F54784&appskey=7C685402983973DBB6FCC589F2417511) being:

```txt
      ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
     DevAddr = 260122DA (Big Endian)
       FCtrl = 01
        FCnt = 0008 (Big Endian)
       FOpts = 02

```

Here, `FCtrl` [indicates](https://lora-alliance.org/sites/default/files/2018-07/lorawan1.0.3.pdf#page=17) that there’s 1 byte in `FOpts`:

> ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/8/8/889361ce4453f17a46af5cee57f9796e24b40580.png)

And that one byte [is a LinkCheckReq](https://lora-alliance.org/sites/default/files/2018-07/lorawan1.0.3.pdf#page=22):

> ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/2/9/29495acf433b1b9b637f4809e0da2105b183495a.png)

The response is, e.g., [60DA2201260307000210016C6E99E6](http://runkit.io/avbentem/lorawan-packet-decoder/branches/master?data=60DA2201260307000210016C6E99E6&nwkskey=95C823FBA73BBFD98DA82C2539F54784&appskey=7C685402983973DBB6FCC589F2417511), or:

```txt
      ( FHDR = DevAddr[4] | FCtrl[1] | FCnt[2] | FOpts[0..15] )
     DevAddr = 260122DA (Big Endian)
       FCtrl = 03
        FCnt = 0007 (Big Endian)
       FOpts = 021001

```

Here, the 0x02 in `021001` decodes to LinkCheckAns, [along with](https://lora-alliance.org/sites/default/files/2018-07/lorawan1.0.3.pdf#page=23):

> ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/4/d/4d1b1def8dfefda6798b87fa65e6210ff7823e3d.png)

So, 0x10 = margin = 16 dB, and 0x01 = gateway count = 1.

Enjoy 🙂

---

<div class="post-metadata">

**Author:** ![rharte](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/rharte/32/37824_2.png) [@rharte](https://www.thethingsnetwork.org/forum/u/rharte)\
**Post date:** [November 26, 2018, 9:48am UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/19 "2018-11-26T09:48:10Z")

</div>

> [@arjanvanb](#):
>
> Also, for LinkCheckAns you do not need to schedule a downlink yourself, I think.

That is correct. The LinkCheckAnswer will come directly in the network reply in RX1 or RX2.

---

<div class="post-metadata">

**Author:** ![strangerFlo](https://www.thethingsnetwork.org/forum/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@strangerFlo](https://www.thethingsnetwork.org/forum/u/strangerFlo)\
**Post date:** [November 29, 2018, 12:31pm UTC](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981/20 "2018-11-29T12:31:17Z")

</div>

Ahaaaa … Thank you all very much for your great support, and in particular I want to thank you Arjan, for providing the solution!  
Now it also works for me. 😃  
 ![uplink_with_received_%20linkcheck_data](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/e/b/eb3deb131ad1a248227ddc5d4198e17c48501bec.png)

Could someone add a hint to the API documentation, because this does not seem that obvious to me?

[Next page](https://www.thethingsnetwork.org/forum/t/ttn-node-link-check-does-not-work/19981.md?page=2)
