LoRaWAN® Regional Parameters in the Arduino® MKRWAN 1310

Learn how to set up specific LoRaWAN regional parameters in the LoRa® module of the Arduino® MKR WAN 1310 board using the Arduino MKRWAN library.

Introduction

In this tutorial, we will learn how to set up specific LoRaWAN® regional parameters for the LoRa® module (Murata CMWX1ZZABZ-078) of the Arduino® MKR WAN 1310 and Arduino® MKR WAN 1300 boards. For doing this, we are going to use the Arduino MKRWAN library functionalities.

Goals

Required Hardware and Software

LoRaWAN® Networking Protocol Overview

LoRaWAN® is a "Low Power Wide Area (LPWA) end-to-end system architecture designed to wirelessly connect battery operated "things" to the internet in regional, national or global networks. The architecture includes protocol standards and features that support low-cost, mobile, and secure bi-directional communication for Internet of Things (IoT), machine-to-machine (M2M), smart city & industrial applications". LoRaWAN® is optimized for low-power consumption and it is designed to scale from a simple gateway up to a large global network of billions of connected devices.

LoRaWAN® fundamental characteristics are the following:

  • Long-range: typically two to 5 km in urban areas (obstacles) and 5 to 15 km in rural areas.
  • Long battery duration: up to 10 years without a replacement (note that long battery duration will require an increased downlink latency configuration).
  • Low cost: regarding sensors and maintenance.
  • License-free spectrum: LoRaWAN® networks operates on license-free and cost-​free ISM (Industrial, Scientific, Medical) bands; however, region-specific regulations apply.
  • Limited payload: 51 to 256 bytes (depending on data rate).
  • Limited data rate: 0.3 to 27 kbps.

The LoRa Alliance® specifies the LoRaWAN® networking protocol in the LoRaWAN® specification documents. These documents are developed and maintained by the LoRa® Alliance, an open association of collaborating members. As stated before, though LoRaWAN® operates on license-free and cost-​free ISM bands, manufacturers and operators of LoRaWAN® devices still have to fulfill various country-specific regulations.

LoRa Alliance® Regional Parameters Overview

The LoRaWAN® Regional Parameters specification is a companion to the LoRaWAN® Link Layer specification. While the LoRaWAN® Link Layer specification defines the air interface between a compliant end-device (sensor, actuator, tracker, etc.) and a compliant network core, the LoRaWAN® Regional Parameters specification defines the adaptation of the LoRaWAN® Link Layer specification to comply with the various regulations enforced throughout the world on the use of various frequency bands of the unlicensed spectrum which are available.

Also, the LoRaWAN® Regional Parameters specification documents the physical layer configurations required for the compliant operation of LoRaWAN® Link Layer radios using various radio frequency modulation techniques.

The idea behind the LoRaWAN® Regional Parameters specification is to create the smallest number of regional channel plans covering the largest possible number of regulatory regions. With this, complexity is decreased to implementers as well as the certification cost (end-device certification is enumerated by Link Layer, Regional Parameters and channel plan revision).

LoRaWAN® Regional Parameters specifications do not specify everything. They only cover a region by specifying the common denominator. For example, the LoRaWAN® Regional Parameters for Asia only specify a common subset of channels, but there are variations between regulations in Asian countries. Furthermore, each network server operator, for example The Things Network (TTN), is free to select additional parameters, such as additional emission channels.

For more information, you can read the RP002-1.0.2 LoRaWAN® Regional Parameters document here.

Regional Parameters Configuration Example: Australia

Let's use Australia (AU915-928) as an example of how we can set up, or configure, it's specific LoRaWAN® regional parameters in the LoRa® module of our MKR WAN 1310 board and connect it to TTN. TTN also have specific LoRaWAN® protocol characteristics for every region, including Australia, that must be configured. You can read more about The Things Network and the LoRaWAN® Regional Parameters here.

As stated in section 2.8 of the LoRaWAN® Regional Parameters specification, in Australia the LoRaWAN® frequency spectrum has 64 uplink channels available, channels 0 to 63 (125 kHz each), starting at 915.2 MHz which increment every 200 kHz up to 927.8 MHz. There are also 8 additional uplink channels, channels 64 to 71 (500 kHz each), starting at 915.9 MHz which increment every 1.6 MHz up to 927.1 MHz. The frequency spectrum for those is overlapping with the basic 64 channels. For gateway to end-node device communication there are 8 downlink channels, channels 0 to 7 (500 KHz each), starting at 923.3 MHz which increment every 600 KHz up to 927.5 MHz. This information is shown in the table below:

Frequency BandsFrequency Range (MHz)Channels
Australia915.2 - 927.80 - 63
Uplink Sub-BandsFrequency Range (MHz)Channels
Sub-Band 1915.2 - 916.60 - 7
Sub-Band 2916.8 - 918.28 - 15
Sub-Band 3918.4 - 919.816 - 23
Sub-Band 4920.0 - 921.424 - 31
Sub-Band 5921.6 - 923.032 - 39
Sub-Band 6923.2 - 924.640 - 47
Sub-Band 7924.8 - 926.248 - 55
Sub-Band 8926.4 - 927.856 - 63
Additional Sub Band915.9 - 927.164 - 71
Downlink Sub-BandsFrequency Range (MHz)Channels
Downlink Sub-Band923.3 - 927.50 - 7

AU915-928 channel frequencies (source: lora-alliance.org)
AU915-928 channel frequencies (source: lora-alliance.org)

For 8 channel gateways, TTN in Australia uses sub-band 2 plus channel 65 only (uplink). This means that we need to program those specific channels (channel masking) in our MKR WAN 1310 board in order to make it work with a gateway connected to TTN. This can be easily done for our MKR WAN 1310 board using the Arduino MKRWAN library. Note that the downlink channels don't need to be configured.

Channel Masking on the MKR WAN 1310 Board

First, let's make sure our board drivers are installed. If we are using the online IDE, we do not need to install anything. If we are using the offline IDE, we need to go to Tools > Board > Board Manager.... Here we need to look for Arduino SAMD boards (32-bits ARM Cortex M0+) and install the latest version. After installing the drivers remember to select the board and the port, to which it is connected, in the Tools menu.

After installing our board drivers, we need to install also the MKRWAN library. If we are using the online IDE, there is no need to install anything. If we are using the offline IDE, we need to go to Tools > Manage Libraries.... Here we need to search for MKRWAN and install the latest version.

Before we can use the MKRWAN library a firmware update of the LoRa® module of our MKR 1310 board is recommended. Updating the module's firmware can be done easily with the MKRWANFWUpdate_standalone sketch. We can find this sketch in File > Examples > MKRWAN > MKRWANFWUpdate_standalone. After uploading the sketch, we should see the following output in the Arduino IDE Serial Monitor when the firmware update is done:

Updating the firmware of the MKR WAN 1310 LoRa® module.
Updating the firmware of the MKR WAN 1310 LoRa® module.

For enabling or disabling, or masking, specific LoRaWAN® frequency spectrum channels in our MKR WAN 1310 board we can use the enableChannel() and disableChannel() functions from the MKRWAN library. Channel masking should be made in the initialization function like in the example code shown below:

#include <MKRWAN.h> LoRaModem modem; void setup() { int status; // Initialize serial port at 9600 bauds Serial.begin(9600); while (!Serial); loraSetup(); Serial.println("--------------------------------"); Serial.println("- MKR WAN 1310 Channel Masking -"); Serial.println("--------------------------------"); // Print default channels configuration Serial.print("- Default mask: "); Serial.println(modem.getChannelMask()); // Disable all channels Serial.println("- Disabling all channels..."); for (unsigned int i = 0; i < 72; i++) { modem.disableChannel(i); } // Print current channels configuration Serial.print("- Current mask: "); Serial.println(modem.getChannelMask()); // Enable AU915-928 channels // LoRaWAN® Regional Parameters and TTN specification: channels 8 to 15 plus 65 Serial.println("- Enabling channels 8 to 15 plus 65..."); for (unsigned int i = 8; i <= 15; i++) { modem.enableChannel(i); } modem.enableChannel(65); // Print current channels configuration Serial.print("- Current mask: "); Serial.println(modem.getChannelMask()); } void loraSetup() { // Initialize LoRa module with the AU915-928 region parameters if (!modem.begin(AU915)) { Serial.println("- Failed to start LoRa module!"); while (1); }; delay(5000); } void loop() {}

After uploading the sketch, we should see the following output in the Arduino IDE Serial Monitor:

Channel Masking in the MKR WAN 1310 board.
Channel Masking in the MKR WAN 1310 board.

ff000000f000ffff00020000 is the channel mask we get if we block all channels except those from sub-band 2 plus channel 65. Now, with this mask and the sendMask() function from the MKRWAN library, we can try a common Over-The-Air-Activation (OTAA) join to TTN like in the example code shown below:

#include <MKRWAN.h> #include "arduino_secrets.h" LoRaModem modem; // Enter your sensitive data in the secret tab or arduino_secrets.h String appEui = SECRET_APP_EUI; String appKey = SECRET_APP_KEY; void setup() { // Initialize serial port at 9600 bauds Serial.begin(9600); while (!Serial); // Initialize LoRa module with the AU915-928 region parameters if (!modem.begin(AU915)) { Serial.println("Failed to start module"); while (1) {} }; // Device module version and EUI delay(5000); Serial.print("Your module version is: "); Serial.println(modem.version()); Serial.print("Your device EUI is: "); Serial.println(modem.deviceEUI()); // Enable AU915-928 channels // LoRaWAN® Regional Parameters and TTN specification: channels 8 to 15 plus 65 modem.sendMask("ff000001f000ffff00020000"); Serial.println(modem.getChannelMask()); modem.setADR(true); join(); } void join() { // Try to connect int connected = modem.joinOTAA(appEui, appKey); if (!connected) { Serial.println("Something went wrong, retrying..."); join(); } } void loop(){}

That's it! Now you should be able to configure your own LoRaWAN® Regional Parameters using the enableChannel(), disableChannel() and sendMask() functions.

Conclusion

In this tutorial we learned how to set up specific LoRaWAN® Regional Parameters for the LoRa® module (Murata CMWX1ZZABZ-078) of the Arduino® MKR WAN 1310 board using the enableChannel(), disableChannel() and sendMask() functions from the MKRWAN library.

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.