RAK811: Downlink TTN to Node with LoRaWAN

Issue: Can’t get downlink message to node.

Setup:

  • Board with Arduino IDE.
  • RAK811 Breakout Board for end-node.
  • RAK2247 for gateway.

Server: TTN

Details: I’m testing it using the WisNode-Arduino-Library running the Join Network OTAA Example as I want to get the downlink through LoRaWAN not P2P.

As TTN LoRaWAN explanation says: “Downlink messages should be avoided if possible, and if you send downlink, keep the payload small.”, but it should word as I’m sending only 01 or 02.

My code is the example code added the receive part that reads from the Breakout Board Serial.

Another strange thing that happens is that TTN’s console only sends my downlink when the Node sends data to it, so if I set the node as a receiver only, the data keeps as scheduled forever on TTNs.

void setup() {
  DebugSerial.begin(115200);
  while(DebugSerial.available())
  {
    DebugSerial.read(); 
  }

  while(!DebugSerial) delay(10);
  Serial.println("RAK811: Join Network OTAA Example");
  
  ATSerial.begin(115200); //set ATSerial baudrate:This baud rate has to be consistent with  the baud rate of the WisNode device.
  while(ATSerial.available())
  {
    ATSerial.read(); 
  }

  RAKLoRa.rk_setWorkingMode(0);
  
  RAKLoRa.rk_getVersion();  //get RAK811 firmware version
  DebugSerial.println(RAKLoRa.rk_recvData());  //print version number

  DebugSerial.println(F("Start init RAK811 parameters..."));
 
  if (!InitLoRaWAN())  //init LoRaWAN
  {
    DebugSerial.println(F("Init error,please reset module.")); 
    while(1);
  }

  DebugSerial.println(F("Start to join LoRaWAN..."));
  while(!RAKLoRa.rk_joinLoRaNetwork(60))  //Joining LoRaNetwork timeout 60s
  {
    DebugSerial.println();
    DebugSerial.println(F("Rejoin again after 5s..."));
    delay(5000);
  }
  DebugSerial.println(F("Join LoRaWAN success"));

  if(!RAKLoRa.rk_isConfirm(0))  //set LoRa data send package type:0->unconfirm, 1->confirm
  {
    DebugSerial.println(F("LoRa data send package set error,please reset module.")); 
    while(1);    
  }
}

bool InitLoRaWAN(void)
{
  if(RAKLoRa.rk_setJoinMode(JOIN_MODE))  //set join_mode:OTAA
  {
    if(RAKLoRa.rk_setRegion(1))  //set region AU915
    {
      if (RAKLoRa.rk_initOTAA(DevEui, AppEui, AppKey))
      {
        DebugSerial.println(F("RAK811 init OK!"));  
        return true;    
      }
    }
  }
  return false;
}

void loop() {
  DebugSerial.println(F("Start send data..."));
  if (RAKLoRa.rk_sendData(1, buffer))
  {    
    for (unsigned long start = millis(); millis() - start < 5000L;)
    {
      String ret = RAKLoRa.rk_recvData();
      if(ret != NULL)
      { 
        DebugSerial.println(ret);
      }
      if((ret.indexOf("OK")>0)||(ret.indexOf("ERROR")>0))
      {
        DebugSerial.println(F("Go to Sleep."));
        RAKLoRa.rk_sleep(1);  //Set RAK811 enter sleep mode
        delay(10000);  //delay 10s
        RAKLoRa.rk_sleep(0);  //Wakeup RAK811 from sleep mode
        break;
      }
    }
  }

 // recvP2P just reads the serial until /0 and trim it later
  DebugSerial.println(F("Start receiving..."));
  for (unsigned long start = millis(); millis() - start < 100000L;)
  {
    String ret2 = RAKLoRa.rk_recvP2PData();
    if(ret2 != NULL)
    {        
      DebugSerial.println(ret2);
    }
  }
}

My gateway service status moments after the scheduled downlink was delivered.

Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: src/jitqueue.c:448:jit_print_queue(): INFO: [jit] queue is empty
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: ### [GPS] ###
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: # GPS sync is disabled
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: ##### END #####
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: JSON up: {"stat":{"time":"2020-10-24 12:05:41 GMT","rxnb":0,"rxok":0,"rxfw":0,"ackr"
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: INFO: Received pkt from mote: 26032F33 (fcnt=1)
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: JSON up: {"rxpk":[{"tmst":1939074315,"chan":1,"rfch":0,"freq":917.000000,"stat":1,"m
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: INFO: [down] PULL_RESP received  - token[0:58] :)
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: JSON down: {"txpk":{"imme":false,"tmst":1940074315,"freq":923.9,"rfch":0,"powe":20,"
Oct 24 13:05:43 raspberrypi ttn-gateway[10024]: INFO: == used txlut index:11

This is normal & part of the LoRaWAN specification for Class A devices.

I haven’t used the RAK library for downlinks, as downlinks should be avoided at all costs, but I have seen downlinks arrive just fine on RAK811 when connected to a serial<>USB and using the RAK serial tool.

How close do you have the device & gateway - if they are in the same room, you need a chunk of metal or a monitor between them otherwise you will just overload the input stage on the RAK811.

As for downlink size, the reason TTN community hates them is that for LoRaWAN, downlinks render the gateway deaf on all channels whilst it is transmitting - so no uplinks can be heard at all. And if the device is some distance away requiring a higher DR, it could be transmitting for over a second.

Let me know how you get on with the serial tool.

1 Like

In the end the answer was pretty much obvious, just change the if(ret != NULL) to if(ret != "") and it will work.
For those that may have this question latter on, here is the code (basically the rak’s example) with some images showing that it works.

void loop() {
  DebugSerial.println(F("Start send data..."));
  if (RAKLoRa.rk_sendData(1, buffer))
  {    
    for (unsigned long start = millis(); millis() - start < 60000L;)
    {
      String ret = RAKLoRa.rk_recvData();
      if(ret != "")
      { 
        DebugSerial.println(ret);
      }
    }
  }
}

TTNs Console

Arduino Serial Monitor

09:11:17.926 -> Start send data...
09:11:17.926 -> hi:123.45
09:11:17.926 -> at+send=lora:1:
09:11:21.090 -> OK 
09:11:21.090 -> at+recv=1,-66,7,3:aabbcc
2 Likes

Good spot - I could have spun my wheels on that one for a few hours!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.