RUI3 (RAK Unified Interface 3) - RAK4631
Joining and Sending Data on LoRa® Network

Data Structures

class  RAKLorawan::rety
 
class  RAKLorawan::cfm
 
class  RAKLorawan::cfs
 
class  RAKLorawan::njm
 
class  RAKLorawan::njs
 

Functions

bool join ()
 
bool send (uint8_t length, uint8_t *payload, uint8_t fport, bool confirm, uint8_t retry)
 
bool lpsend (uint8_t port, bool ack, uint8_t *payload, int length)
 
bool registerRecvCallback (service_lora_recv_cb callback)
 
bool registerJoinCallback (service_lora_join_cb callback)
 
bool registerSendCallback (service_lora_send_cb callback)
 

Detailed Description

Function Documentation

◆ join()

bool join ( )
Description
This api does a join request to the network
Syntax
api.lorawan.join() api.lorawan.join(join_start, auto_join, auto_join_period, auto_join_cnt)
Parameters
join_startmanually join network: 0 means stop to join network; 1 means start to join network.
auto_joinautomatically join network: 0 means stop automatically joining network; 1 means start automatically joining network.
auto_join_periodthe join attempt period. The acceptance values are 7 to 255 (in seconds).
auto_join_cntthe maximum number of join attempts. The acceptance values are 0 to 255 (in seconds).
Returns
bool
Return values
TRUEfor success
FALSEfor join failure
Example
  // OTAA Device EUI MSB
  uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  // OTAA Application EUI MSB
  uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
  // OTAA Application Key MSB
  uint8_t node_app_key[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};

  void setup()
  {
      Serial.begin(115200);

      api.lorawan.appeui.set(node_app_eui, 8);
      api.lorawan.appkey.set(node_app_key, 16);
      api.lorawan.deui.set(node_device_eui, 8);

      api.lorawan.band.set(4);
      api.lorawan.njm.set(1);
      api.lorawan.join();

      //wait for Join success
      while (api.lorawan.njs.get() == 0)
      {
        Serial.print("Waiting for Lorawan join...");
        api.lorawan.join();
        delay(10000);
      }
  }

  void loop()
  {
  }

◆ send()

bool send ( uint8_t  length,
uint8_t *  payload,
uint8_t  fport,
bool  confirm,
uint8_t  retry 
)
Description
This api provides the way to send data on a dedicated port number
Syntax
api.lorawan.send(length, payload, fport) api.lorawan.send(length, payload, fport, confirm) api.lorawan.send(length, payload, fport, confirm, retry)
Parameters
lengththe length of the payload
payloadthe date to uplink
fportallow 1 ~ 223
confirmOverride cfm setting to get confirm message from gateway (just for this time)
retryOverride rety setting to retry if sending failed (just for this time)
Returns
bool
Return values
TRUEfor sending uplink success
FALSEfor sending uplink
Example
  // OTAA Device EUI MSB
  uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  // OTAA Application EUI MSB
  uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
  // OTAA Application Key MSB
  uint8_t node_app_key[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};

  void setup()
  {
      Serial.begin(115200);

      api.lorawan.appeui.set(node_app_eui, 8);
      api.lorawan.appkey.set(node_app_key, 16);
      api.lorawan.deui.set(node_device_eui, 8);

      api.lorawan.band.set(4);
      api.lorawan.njm.set(1);
      api.lorawan.join();

      //wait for Join success
      while (api.lorawan.njs.get() == 0)
      {
        Serial.print("Waiting for Lorawan join...");
        api.lorawan.join();
        delay(10000);
      }
  }

  void loop()
  {
      uint8_t payload[] = "example";

      if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
          Serial.println("Send Success");
      } else {
          Serial.println("Send fail");

      }

      delay(5000);
  }

◆ lpsend()

bool lpsend ( uint8_t  port,
bool  ack,
uint8_t *  payload,
int  length 
)
Description
This api provides a way to send long packet(1024 bytes) text data
Syntax
api.lorawan.lpsend(port, ack, payload, length)
Parameters
portapplication port to be transmitted
ackindicate this is a confirmed message or not
payloadthe date you want to send
lengththe length of the paylaod
Returns
bool
Return values
TRUEfor sending data success
FALSEfor sending data failure
Example
  // OTAA Device EUI MSB
  uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  // OTAA Application EUI MSB
  uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
  // OTAA Application Key MSB
  uint8_t node_app_key[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};

  void setup()
  {
      Serial.begin(115200);

      api.lorawan.appeui.set(node_app_eui, 8);
      api.lorawan.appkey.set(node_app_key, 16);
      api.lorawan.deui.set(node_device_eui, 8);

      api.lorawan.band.set(4);
      api.lorawan.njm.set(1);
      api.lorawan.join();

      //wait for Join success
      while (api.lorawan.njs.get() == 0)
      {
        Serial.print("Waiting for Lorawan join...");
        api.lorawan.join();
        delay(10000);
      }
  }

  void loop()
  {
      uint8_t payload[] = "12345678901234567890";

      if (api.lorawan.lpsend(129, 1, payload, sizeof(payload))) {
          Serial.println("Send Success");
      } else {
          Serial.println("Send fail");

      }

      delay(5000);
  }

◆ registerRecvCallback()

bool registerRecvCallback ( service_lora_recv_cb  callback)
Description
This API is used to register a callback function, so that application can be notified on receiving LoRaWAN data.
Syntax
api.lorawan.registerRecvCallback(service_lora_recv_cb callback)
Parameters
Thecallgback function
Returns
bool
Return values
TRUEfor setting callback function success
FALSEfor setting callback function failure
Example
void recv_cb(SERVICE_LORA_RECEIVE_T *data) {
  Serial.println("Something received!");
  for (int i = 0 ; i < data->BufferSize ; i++) {
    Serial.printf("%x", data->Buffer[i]);
  }
  Serial.print("\r\n");
}

void join_cb(int32_t status) {
  Serial.printf("Join status: %d\r\n", status);
}

void send_cb(int32_t status) {
  Serial.printf("Send status: %d\r\n", status);
}

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// OTAA Application Key MSB
uint8_t node_app_key[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();
    api.lorawan.registerRecvCallback(recv_cb);
api.lorawan.registerJoinCallback(join_cb);
    api.lorawan.registerSendCallback(send_cb);

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    } else {
        Serial.println("Send fail");

    }

    delay(5000);
}

◆ registerJoinCallback()

bool registerJoinCallback ( service_lora_join_cb  callback)
Description
This API is used to register a callback function, so that application can be notified when joining process is done.
Syntax
api.lorawan.registerJoinCallback(service_lora_join_cb callback)
Parameters
Thecallgback function
Returns
bool
Return values
TRUEfor setting callback function success
FALSEfor setting callback function failure
Example
void recv_cb(SERVICE_LORA_RECEIVE_T *data) {
  Serial.println("Something received!");
  for (int i = 0 ; i < data->BufferSize ; i++) {
    Serial.printf("%x", data->Buffer[i]);
  }
  Serial.print("\r\n");
}

void join_cb(int32_t status) {
  Serial.printf("Join status: %d\r\n", status);
}

void send_cb(int32_t status) {
  Serial.printf("Send status: %d\r\n", status);
}

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// OTAA Application Key MSB
uint8_t node_app_key[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();
    api.lorawan.registerRecvCallback(recv_cb);
api.lorawan.registerJoinCallback(join_cb);
    api.lorawan.registerSendCallback(send_cb);

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    } else {
        Serial.println("Send fail");

    }

    delay(5000);
}

◆ registerSendCallback()

bool registerSendCallback ( service_lora_send_cb  callback)
Description
This API is used to register a callback function, so that application can be notified when uplink process is done.
Syntax
api.lorawan.registerSendCallback(service_lora_send_cb callback)
Parameters
Thecallback function
Returns
bool
Return values
TRUEfor setting callback function success
FALSEfor setting callback function failure
Example
void recv_cb(SERVICE_LORA_RECEIVE_T *data) {
  Serial.println("Something received!");
  for (int i = 0 ; i < data->BufferSize ; i++) {
    Serial.printf("%x", data->Buffer[i]);
  }
  Serial.print("\r\n");
}

void join_cb(int32_t status) {
  Serial.printf("Join status: %d\r\n", status);
}

void send_cb(int32_t status) {
  Serial.printf("Send status: %d\r\n", status);
}

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// OTAA Application Key MSB
uint8_t node_app_key[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();
    api.lorawan.registerRecvCallback(recv_cb);
api.lorawan.registerJoinCallback(join_cb);
    api.lorawan.registerSendCallback(send_cb);

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    } else {
        Serial.println("Send fail");

    }

    delay(5000);
}