Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

LoRaWan® examples

1. Overview

If you are working on a battery powered solution and want to minimize the power consumption of the WisBlock, please have a look at Low Power Example. There is a separate example that concentrates on low power consumption.

This example shows how to setup the WisBlock as a LoRaWan® sensor node. There are two examples available, one for nodes with ABP network join function and one for nodes using the OTAA network join function. If you want to use LoRaWan® communication you need to define a region. The defined region tells the library which frequency and which channels should be used. Valid regions are:

  • LORAMAC_REGION_AS923
  • LORAMAC_REGION_AU915
  • LORAMAC_REGION_CN470
  • LORAMAC_REGION_CN779
  • LORAMAC_REGION_EU433
  • LORAMAC_REGION_EU868
  • LORAMAC_REGION_IN865
  • LORAMAC_REGION_KR920
  • LORAMAC_REGION_US915

The region is selected while calling lmh_init. Example:

err_code = lmh_init(&g_lora_callbacks, g_lora_param_init, TRUE, CLASS_A, LORAMAC_REGION_US915);

In addition you need keys to register the device.

ALL KEYS ARE MSB!

Keys required for OTAA

  • Device EUI if you want to use ABP registration of the device
  • Application EUI
  • Application Key, the AES encryption/decryption cipher application key

Keys required for ABP

  • Device address
  • Network Session Key
  • App Session Key

The devices must be registered on your LoRaWan® server before they can send and receive data. The above mentioned EUIs and keys can be obtained from your LoRaWan® server. If you use a RAK gateway with an integrated LoRaWan® server or want to use TheThingsNetwork server you can find a tutorial here

2. Hardware Required

To build the LoRa® system. With just one WisBlock Core RAK4631 plugged into the WisBlock Base RAK5005-O board the system is ready to be used.

  • WisBlock Base RAK5005-O
  • WisBlock Core RAK4631

The RAK4631 is the WisBlock Core which can be connected to CPU SLOT of WisBlock via pin to pin groove like below. Besides, it provides SWD port to download via Jlink. Two antenna (BLE and LoRa®). Screws of four corners help stabilize connection with WisBlock.

rak4631-connectors

3. Software Required

3.1 Install LoRaWAN library

After install Arduino IDE and BSP according to the Quick Start Guide, you can install LoRaWAN® library now. Step as below:

  • Start the Arduino IDE
  • Open Library Manager, search for sx126x-Arduino, and install

lib-sx12x-install

3.2 Feature of SX126x_Arduino_base library

The library is an excellent library, supports below:

  • LoRaWAN® protocol V1.0.2
  • Class A and Class C
  • Region EU868/US915/AU915/KR920/AS923/IN865
  • OTAA and ABP
  • Dutycycle
  • ADR/Datarate/Tx power configuration
  • Confirm/Unconfirm
  • DevEUI/AppEUI/AppKey/DevAddr/NwsKey/AppsKey configuration
  • Send data port

3.3 Run a simple example

RAKwireless provides a lot of example based on this library. Here choose a simple example to show how to develop a LoRaWAN® application.

3.3.1 Scene description

Download the example from https://github.com/RAKWireless/WisBlock/tree/master/examples/communications/LoRa/LoRaWAN/LoRaWAN_OTAA/ . The example will communicate with server in EU868, join type in OTAA. And send "hello" to server period.

3.3.2 Gateway configuration

To test the example, we build node like below in ChirpStack (open-source LoRaWAN® Network Server stack, TTN is also supported and tested). And we can obtain the DeviceEUI, AppEUI, AppKey, copy them. The detailed parameters is below:

  • Region: EU868
  • Join Type: OTAA
  • Class: A

lora-gateway-1

3.3.3 Node configuration

Then open the example in Arduino, fill the DeviceEUI, AppEUI, AppKey in the code like below:

//OTAA keys !!!! ALL KEYS ARE MSB !!!
uint8_t nodeDeviceEUI[8] = {0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x33, 0x33};
uint8_t nodeAppEUI[8] = {0xB8, 0x27, 0xEB, 0xFF, 0xFE, 0x39, 0x00, 0x00};
uint8_t nodeAppKey[16] = {0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x33, 0x33, 0x33, 0x33, 0x33};

3.3.4 Compile and download

There is a USB port on WisBlock. It is a debug port for RAK4631 with three function:

  • Power supply
  • Download port in Arduino
  • Communication with RAK4631, incluing log print and command from PC

Connect WisBlock to PC via USB. Arduino will recognize the board. The red led is on means power up. Go into tools and choose like below.

Then click Upload (arrow button), it will compile and download to RAK4631 automatically. The blue led is on means download ok.

ard-compile-finished

3.3.5 Log print and server data

Go into Tools, choose the port (Adafruit Feather nRF52840 Express), open Serial Monitor. Log will show as below. It will join automatically and send 'hello!' to server per 20s :

lora-otaa-log

At the same time, server will show the data from RAK4631.

lora-gateway-3

It is a very easy way for users to finish their first LoRaWAN® trip. But most users want to apply LoRaWAN® to their own application. RAKwireless also provide a efficient way for them.

LoRa® is a registered trademark or service mark of Semtech Corporation or its affiliates. LoRaWAN® is a licensed mark.