LoRaWAN Demo Project Tutorial

The Blog Post contains a tutorial, which presents an example of using LoRaWAN network for the IoT applications.

The prepared program was tested on the B-L072Z-LRWAN1 development kit, which was sending the messages to the TNN(The Things of Network), using the LoRaWAN network.

As the LoRaWAN network’s broker lpnGate was used. Its description is presented under this link.

How does the demo project work?

The program, which was flashed into the LoRaWAN End Device B-L072Z-LRWAN1, handles interrupts, generated by pressing of the USER BUTTON (blue button located on the module’s surface) and in the result of the timer’s overflow. The program contains 2 ISRs, one for USER BUTTON Pressing Interrupts and the other for Timer Overflow Interrupts.

In the first routine, program turn on/off the LED1 diode and sets up a flag, which enables us to send the USER BUTTON Pressing message code to the TTN’s Cloud.

The second ISR changes a state of LED2 diode, after every 2 seconds and sets up the flag, enabling to send the Timer Overflow message code to TTN. The designed project gives a possibility to debug LoRaWAN communication via the serial monitor.

Device configuration

In the first step, you need to prepare some example of the B-L072Z-LRWAN1 development kit.

Next, you need to get and configure LPN Gate, according to the following instruction.

Add application

In the first step, go into the Things of Network’s homepage and sign on your TTN’s account (if you don’t have it yet, just register).

In the next step, put a mouse cursor on your avatar and chose the option Console->Applications.

If you want to add the new End-Device, click on the option Add application. There insert your’s application ID.

Device registration

TTN will create your new application. Next, you need to register it. Click the option Devices->register device. You need to insert your Device’s ID and it’s EUI (you chose its value).

After, that TTN should generate Application EUI and Key for the newly registered device.

TTN’s descriptor configuration

To process received message codes, sent from the End-Device, it is necessary to create the function of the message descriptor. TTN’s descriptors have to be designed in JavaScript language.

To configure the descriptor’s function, on the TTN’s homepage, sign on your account. Go to the Console->Applications option. Choose your device and click on the Payload Formats option.

There click on the decoder option. In the given field, insert the descriptor’s function. For the LoRaWAN Demo Project, the descriptor has the following template:

function Decoder(bytes, port) {
  // Decode plain text; for testing only
  return {
      myTestValue: String.fromCharCode.apply(null, bytes)
  };
}

After that, save payload function. You can also test, if your function process, received data properly. In the label Payload, insert exemplary data(byte string) and click on the option Test. Below, you should see the function’s result.

Prepare project in Mbed Online Compiler

Download mbed-os-example-lorawan project

The Demo Project was developed in Mbed Online Compiler. It gives for its users a possibility not only for code development of applications, based on the Mbed OS, but also for its compilation.

To configure and compile the project, go to the Mbed homepage and sign on your account (if you don’t have it yet, just register it.) When you log on your Mbed account, choose the option Compiler. You should be forwarded to the Mbed Online Compiler.

In the Program Workspace, match My Programs directory and choose the option Import. In the label Search, type the name of the exemplary LoRaWAN Project, created by Mbed OS Group:

mbed-os-example-lorawan

Choose a version of this project, created by Team mbed-os-examples and click Enter. Remember, that you need to import this project as a program.

Import files from the LoRaWAN Demo Project’s repository

First, you need to download and unpack from demo_project.zip file, main code and configuration files for the LoRaWAN Demo Project setup.

Now, you need to replace main.cpp and configuration files (mbed_app.json and the files, placed in the config directory) with the equivalent files from the demo_project.zip file. First, delete previous versions of these files from the mbed-os-example-lorawan program. Remove also unnecessary header file DummySensor.h.

Next, in Program Workspace, match the mbed-os-example-lorawan project and click on the option Import->Upload. Upload main.cpp, SX127X_example_config.json, mbed_app.json files and import it into the project.

Set up import name as “package”. Mbed Online Compiler will upload it to the package program.

Move each file from package program to the appropriate locations in the mbed-os-example-lorawan program (remember that SX127X_example_config.json, should be placed in config directory in the mbed-os-example-lorawan program) and delete the package program.

Set up Lora configuration files

In the mbed_app.json and SX127X_example_config.json files for the JSON Elem “target_overrides”, set up appropriate values of the following fields:

  • lora.device-eui
  • lora.application-eui
  • lora.application-key

For the given example of the End-Device, you need to insert the following values of these JSON fields:

"lora.device-eui": "{ 0x07, 0x00, 0xB3, 0x0D, 0x50, 0x7E, 0x0D, 0x00 }",
"lora.application-eui": "{ 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x02, 0x96, 0x72 }",
"lora.application-key": "{ 0x0B, 0x24, 0x21, 0x68, 0xBC, 0x78, 0x95, 0x42, 0x82, 0x62, 0x46, 0x3E, 0xFD, 0x83, 0x7B, 0x92 }"

 

Compile the project

In the end, choose the End-Device’s platform (click on the option “No device selected”).

In this example, it should be DISCO-L072-LRWAN1. If it isn’t this platform, you should choose the option “Add Board”.

It will redirect you to the following webpage. Search for the DISCO-L072-LRWAN1 platform and add it to your Mbed Compiler.

In the Mbed Online Compiler click the option “Compile” in the menu bar. After the successful compilation, download the appropriate .bin format file.

Run the LoRaWAN Demo Project

In the end, connect your B-L072Z-LRWAN1 End-Device to your PC via USB. In the filesystem, you should see the DIS_L072Z device, attached to your PC. To see log messages on the serial monitor, check the name of a connected device in the Terminal, by using the following command:

$ dmesg

It should be visible in the Terminal as ttyACM0 device:

[ 7337.681261] usb 1-1.3: Product: STM32 STLink
[ 7337.681263] usb 1-1.3: Manufacturer: STMicroelectronics
[ 7337.681264] usb 1-1.3: SerialNumber: 0665FF353830523457161547
[ 7337.736348] usb-storage 1-1.3:1.1: USB Mass Storage device detected
[ 7337.736699] scsi host6: usb-storage 1-1.3:1.1
[ 7337.737115] cdc_acm 1-1.3:1.2: ttyACM0: USB ACM device
[ 7338.768014] scsi 6:0:0:0: Direct-Access     MBED     microcontroller  1.0  PQ: 0 ANSI: 2
[ 7338.768402] sd 6:0:0:0: Attached scsi generic sg2 type 0
[ 7338.769164] sd 6:0:0:0: [sdb] 456 512-byte logical blocks: (233 kB/228 KiB)
[ 7338.769776] sd 6:0:0:0: [sdb] Write Protect is off
[ 7338.769778] sd 6:0:0:0: [sdb] Mode Sense: 03 00 00 00
[ 7338.770380] sd 6:0:0:0: [sdb] No Caching mode page found
[ 7338.770385] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[ 7338.792416] sd 6:0:0:0: [sdb] Attached SCSI removable disk
[ 8308.981091] TCP: eno1: Driver has suspect GRO implementation, TCP performance may be compromised.

Run minicom (you need to have installed minicom on your PC), serial monitor, for the connected device:

$ sudo minicom -b 115200 -o -D /dev/ttyACM0

Then flash your platform with the compiled FW, by moving built binary file to the DIS_L072Z directory. After a few seconds, you should see the following log messages on the serial monitor.

Mbed LoRaWANStack initialized

 CONFIRMED message retries : 3

 Adaptive data  rate (ADR) - Enabled

 Connection - In Progress ...

 Connection - Successful
Timer Overflow Interrupt has been executed. Code: 15, Message: Timer overflow.
 2 bytes scheduled for transmission

 Message Sent to Network Server
Timer Overflow Interrupt has been executed. Code: 15, Message: Timer overflow.
 2 bytes scheduled for transmission

 Message Sent to Network Server
Timer Overflow Interrupt has been executed. Code: 15, Message: Timer overflow.
 2 bytes scheduled for transmission

 Message Sent to Network Server
Timer Overflow Interrupt has been executed. Code: 15, Message: Timer overflow.
 2 bytes scheduled for transmission

 Message Sent to Network Server
Timer Overflow Interrupt has been executed. Code: 15, Message: Timer overflow.
 2 bytes scheduled for transmission

 Message Sent to Network Server
Timer Overflow Interrupt has been executed. Code: 15, Message: Timer overflow.
 2 bytes scheduled for transmission

 Message Sent to Network Server
USER BUTTON Interrupt has been executed. Code: 10, Message: USER BUTTON pressed.
 2 bytes scheduled for transmission

 Message Sent to Network Server
USER BUTTON Interrupt has been executed. Code: 10, Message: USER BUTTON pressed.
 2 bytes scheduled for transmission

 Message Sent to Network Server
Timer Overflow Interrupt has been executed. Code: 15, Message: Timer overflow.
 2 bytes scheduled for transmission

The End-Device should turn on LED2, after every 2 seconds (the result of handling Timer Overflow IRQs) and it should turn on/off LED1 when the user presses the blue button (the result of handling USER BUTTON Pressing IRQs).

Check the results in the TTN’s Cloud

To see data, sent by the End-Device to the TTN, open your Application’s device list, by clicking this link, choose your device and click the option Data. You should see similar results:

Summary

The prepared tutorial presents a single example of possible LoRaWAN applications, using lpnGate product. Each LPN Plant’s client can use, the prepared LoRaWAN Demo Project, for his/her aims, such as temperature, pressure or acceleration measurements. If you have any questions for us, please contact with us.

If you are interested in the purchase of the lpnGate products, go to this link.