Software

From Lorauino Wiki
Jump to: navigation, search

Lorauino board has a library that you need to add to your sketches to use the LoRaWan radio section. You can download the latest version here

https://github.com/gimasi/lorauino

Add the files in your sketches.

Here are some example on how to use the library.

void setup() {
 
  // put your setup code here, to run once:
 
  Serial.begin(9600);
 
 
  // Uncomment this to suppress traces
  // LoRaWan_verbose = false;
 
  // Initialize communication with LoRaWan modem
  LoRaWan_init();
 
  // Uncomment to set the device to Class C. By default the modem is class A
  LoRaWan_class("C");
 
  // Start joining procedure to register on the network
  //LoRaWan_join ("0200000000EEFFC0", "020000FF020000FF", "AB89EFCD2301674554761032DCFE98BA");
 
  // Alternative registration procedure: Activation by personalization
  LoRaWan_personalization("ac000018","8f928ad8a03f096e936d920578dc5367", "ace580ab3807f68f6645fc9e1c804222");
 
}

Joining the Network

To join a LoRaWan network we have two methods:

  1. Over-the-Air activation
    For this activation you need to specify 3 parameters ( all hexadecimal strings ):
    • AppEUI: application identification ( generally in experimental setups this is not used). It must be specified and can be 0000000000000000. This must be 16 chars long ( 8 bytes hex value)
    • DevEUI: unique for each node, equivalente to the MAC address. This must be 16 chars long. ( 8 bytes hex value)
    • AppKey: key that will be used to generate the NwkSKey and AppSKey by the server during the joining procedure. This must be 32 chars long ( 16 bytes hex value).
    void LoRaWan_join (String AppEUI, String DevEUI, String AppKey)
  2. Personalization activation procedure
    In this scenario you still need to specify 3 different parameters:
    • DevAddr: unique for each node
    • NwkSkey: Network Session Key. This must be 32 chars long ( 16 bytes hex value).
    • AppSkey: Application Session Key. This must be 32 chars long ( 16 bytes hex value).
    void LoRaWan_personalization (String DevAddr, String NwkSKey, String AppSKey)

Whether you choise Over-the-Ait or Personalization activation, the parameters that you specify must be also known by the server. The joining procedure must be done in the setup section of the sketch, remember that if the joining fails, for whatever reason, wrong parameter or LoRA network not present, the Lorauino will continue to retry forever and will never start the main loop(). The most common error is that join parameters are not copied correctly in the server provisioning section, so double check everything!

Transmitting

To trasmit a packet to the server you can use this function

void LoRaWan_send(String frame, byte port, boolean acknowledge)

The frame must be an hexadecimal string and the maximum lenght must be of 104, equivalent to 52 bytes. The port is the data port. Be careful, port 0 is dedicated to MAC commands; you cannot transmit data on it. The acknowledge parameter is a Boolean indicating if an acknowledgement must be requested to the network, and the network has to support this.

LoRaWan class A device opens two reception windows just after sending a frame. The network uses these windows to transmit downlink messages to the device. LoRaWan_send function waits this two reception windows to be over and check if a message is received, here the example code:

// Send data buffer
  LoRaWan_send(buf,  1, false);
 
  // Check if RX received
  rx_len = LoRaWan_get_rx();
  if (rx_len) {
      // Process data from buffer LoRaWan_last_rx[i]
      // Just print it in this example
      for (i=0; i<rx_len; i++){
        Serial.println(LoRaWan_last_rx[i], HEX);
      }
  }


Receiving

The Class A receiving example has been described above. In Class C the receiving window is always open so you must regularly poll the rx_buffer in the main loop to verify if data is present with the function:

LoRaWan_get_rx()

See the Example Sketches section for a full example.