Hello,
I have tried to setup a link check on my TTN node using the TTN Arduino API functions. 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