RAK11161 Breakout Board as a Stand-Alone LoRaWAN Using RUI3
This guide demonstrates how to program RAK11161 Breakout Board as a stand-alone LoRaWAN end-device using RUI3 Arduino APIs. To communicate over LoRaWAN, the device must be within range of a functioning LoRaWAN gateway connected to a LoRaWAN network server (LNS), either an external server such as The Things Stack (TTN) or ChirpStack, or a built-in server available on gateways such as WisGate Edge.
Before using the examples in this guide, make sure you have completed the hardware setup and Arduino IDE installation described in the RAK11161 Breakout Board Quick Start Guide.
If you are new to LoRaWAN, here are a few good references about LoRaWAN and gateways:
Connect with The Things Network (TTN)
The Things Stack is an open-source LoRaWAN Network Server for managing LoRaWAN devices and applications across public and private networks. It is maintained by The Things Industries.
This section explains how to set up LoRaWAN communication with The Things Stack (TTN). It covers registering a LoRaWAN gateway on TTN and configuring the RAK11161 for OTAA or ABP activation via RUI3 Arduino APIs.
Figure 1: The Things StackRegister the LoRaWAN Gateway on TTN
Choose the appropriate guide below to register and connect your RAK Gateway to The Things Stack (TTN):
- How to Register a RAK Gateway in TTN V3
- How to Connect RAK Gateways to TTN v3 via UDP
- How to Connect RAK Gateways to TTN v3 Using Basics™ Station (LNS)
- How to Auto-Connect RAK Gateway to TTN (EU1) in Packet Forwarder Mode
- How to Connect RAK Gateways to TTN v3 Using Basics™ Station (CUPS)
Register the RAK11161 on TTN
Step 1: Create a TTN Application
-
Log in to The Things Stack using the account and cluster where your gateway is registered.
-
Once logged in, click **Create application **to create a new application.
Figure 1: The Things Stack Platform- To register an application, enter the required details and necessary information about your application, then click Create application.
Figure 1: Details of the TTN application- If you have no error in the previous step, you should now be on the application console page. The next step is to add end-devices to your TTN application.
Step 2: Register an End Device
Each LoRaWAN end device must be registered and activated using either Over-The-Air Activation (OTAA) or Activation By Personalization (ABP). Follow the steps below to register the module on TTN. Some configuration steps and credentials may differ depending on the selected activation method.
- Go to your application console to register a device. To start adding an OTAA end-device, click + Register end device.
Figure 1: Register end device- To register the board, select Enter end device specifics manually.
Figure 1: Enter end device specifics manually- Set up the appropriate Frequency plan, compatible LoRaWAN version, and Regional Parameters version supported by your device. For OTAA activation, set the JoinEUI to all zeros. This step is not required for ABP activation.
Figure 1: Setting up for your device
Figure 1: Setting the Frequency plan
Figure 1: Setting the LoRaWAN version
Figure 1: Setting the JoinEUI- Click Show advanced activation, LoRaWAN class and cluster settings. Select the activation method supported by your device and set Additional LoRaWAN class capabilities to Class A only.
- OTAA: Select Over the air activation (OTAA). In the JoinEUI field, enter all zeroes to allow the DevEUI to be configured, then click Confirm.
- ABP: Select Activation by personalization (ABP).
Figure 1: Setting up for your device
Figure 1: Configuring OTAA activation settings
Figure 1: Configuring ABP activation settings- Enter the DevEUI credentials of your device into the DevEUI portion. This will automatically generate the specific End device ID of your board. Then generate the credentials required by the selected activation method:
- OTAA: Generate the AppKey, then click Register end device.
- ABP: Generate the Device address, AppSKey, and NwkSKey.
- The DevEUI is unique to each RAK device. Depending on the activation mode, the following credentials are hidden in this section and must be generated for your specific device and application:
- ABP: Device address, AppSKey, and NwkSKey.
- OTAA: AppEUI and AppKey.
- For OTAA, the AppEUI is the same as the JoinEUI.
Figure 1: Generating OTAA credentials
Figure 1: Generating ABP credentials- Finally, click Register end device.
Figure 1: Register end device- You should now be able to see the device on the TTN console after you fully register your device
Figure 1: OTAA device successfully registered to TTN
Figure 1: ABP device registered on TTNConnect with ChirpStack
ChirpStack is an open-source LoRaWAN Network Server for managing LoRaWAN devices and applications. Learn more about ChirpStack.
This section covers connecting a RAK Gateway to ChirpStack, registering a WisDUO module, and configuring the module via RUI3 Arduino APIs.
Figure 1: RAK11720 in the context of the ChirpStack platformRegister the LoRaWAN Gateway on ChirpStack
Choose the appropriate guide below to register and connect your RAK Gateway to ChirpStack:
- How to Register a RAK Gateway in Chirpstack V4
- How to Register a RAK Gateway in Chirpstack V3
- How to Connect RAK Gateways to Chirpstack v3 via UDP
- How to Connect RAK Gateways to Chirpstack v4 via UDP
- How to Connect RAK Gateways to Chirpstack v4 via MQTT
- How to Connect RAK Gateway to Chirpstack v3 Using Basics™ Station (LNS)
- How to Connect RAK Gateway to Chirpstack v4 Using Basics™ Station (LNS)
Register the RAK11161 on ChirpStack
Step 1: Create a ChirpStack Application
- Log in to the ChirpStack server using your account and password.
- Go to the Application section.
Figure 1: Application section- By default, you should create a new application, although you can reuse existing ones. For this setup, create a new Application by clicking on the CREATE button and filling in the required parameters.
Figure 1: Creating a new applicationFor this example, create an Application named rak_node_test.
ChirpStack supports multiple system configurations, although only one is enabled by default.
- Service profile: This field allows you to select the system profile.
- Payload codec: This field determines the parsing method for payload data, such as parsing LPP format data.
Figure 1: Filling in the parameters of an applicationStep2: Register an End Device
- Choose the Application created in the previous step, then select the DEVICES tab.
Figure 1: List of applications created
Figure 1: Device tab of an application- Inside the DEVICE tab, create a new device (LoRaWAN node) by clicking on the + CREATE button.
Figure 1: Add a new device
Figure 1: Chirpstack adding node into the RAK end device- Once the node is created, fill in the necessary data. You can generate a Device EUI automatically by clicking the load icon, or you can manually enter the correct Device EUI in the edit box.
Fill in the parameters requested:
- Device name and Device description: These are descriptive texts about your device.
- Device EUI: This interface allows you to generate a Device EUI automatically by clicking the generate icon. You can also add a specific Device EUI directly in the form.
- Device Profile:
- If you want to join in OTAA mode, select DeviceProfile_OTAA.
- If you want to join in ABP mode, select DeviceProfile_ABP.
Device profiles DeviceProfile_OTAA and DeviceProfile_ABP are only available if you are using the built-in ChirpStack LoRaWAN Server of RAK Gateways.
If you have your own Chirpstack installation, set up the device profile with LoRaWAN MAC version 1.0.4 and LoRaWAN Regional Parameters revision B to make it compatible with RAK end device.
Figure 1: Generate a new Device EUI Step 3: Configure Device Credentials
After registering the module on ChirpStack, configure the corresponding credentials according to the selected activation method, as described in the following sections.
OTAA Device
- If you selected DeviceProfile_OTAA during device registration, configure the Application Key for the device.
Figure 1: Chirpstack OTAA activation- The previously created Application Key can be entered here, or a new one can be generated automatically by clicking the Refresh icon.
Figure 1: Chirpstack OTAA Set Application Keys- Once the Application Key is added to the form, the process can be finalized by clicking on the SET DEVICE-KEYS button. A new device should be listed in the DEVICES tab. The most important parameters, such as the Device EUI, are shown in the summary.
Figure 1: Chirpstack OTAA list of the device in the Device Tab- To end the process, it is a good practice to review that the Application Key is properly associated with this device. The Application Key can be verified in the KEYS(OTAA) tab.
Figure 1: Application key associated with the new deviceStandard OTAA mode requires the Device EUI, Application Key, and Application EUI, but in ChirpStack’s implementation, only the Device EUI and the Application Key are mandatory. The Application EUI is not required and not recorded in the Application tab. Nevertheless, you can reuse the Device EUI as the Application EUI during the configuration on the side of the node.
ABP Device
- If you select DeviceProfile_ABP during device registration, the ChirpStack platform will assume that this device will join the LoRaWAN network using the ABP mode.
Check Disable counting frame verification. During testing, if the module is restarted, the frame counting number will also be reset to zero. This can lead to synchronization issues with the ChirpStack server, which may interpret it as a replay attack. While it's safe to disable this feature for testing purposes, remember to activate it in a production environment.
Figure 1: ChirpStack console, configuring a device-
After selecting the ABP mode, the following parameters appear in the Activation tab:
-
Device Address
-
Network Session Key
-
Application Session Key
-
Figure 1: Chirpstack ABP activation parameters needed- The parameters can either be generated as random numbers by the platform or set with user-defined values. Once these parameters are filled in correctly, the process is completed by clicking on the ACTIVATE DEVICE button.
After registering the device on the LNS, choose the LoRaWAN example that matches your selected activation mode: OTAA or ABP.
Upload OTAA LoRaWAN Example to RAK11161
After successfully registering the module to the LoRaWAN Network Server as an OTAA device, you can proceed with running the LoRaWAN OTAA demo application example.
- Open the example code under RAK WisBlock RUI examples.
Figure 1: OTAA LoRaWAN application example- In the example code, modify the device EUI (DEVEUI) and application key (APPKEY).
- The device EUI (DEVEUI) must match the DevEUI registered on your LoRaWAN network server in the previous section. The DEVEUI is MSB.
// Example OTAA Device EUI MSB
#define OTAA_DEVEUI {0xAC, 0x1F, 0x09, 0xFF, 0xFE, 0x06, 0x72, 0x1E}
- Another important parameter to change is the application key (APPKEY). This parameter must match the AppKey configured on your LoRaWAN network server in the previous section. The APPKEY is MSB.
// Example OTAA Application Key MSB
#define OTAA_APPKEY {0x21, 0x7D, 0xB8, 0x53, 0x3F, 0xA3, 0x38, 0xC8, 0xBC, 0x49, 0x25, 0xCC, 0xDD, 0x66, 0x43, 0x58}
Figure 1: Updating DEVEUI and APPKEY- This guide uses US915 regional band, so you need to update the band in the code as well. Additionally, set up the channel mask (channels 8 to 15 are the most commonly used channels in the US915 band).
if(!(ret = api.lorawan.band.set(5)))
{
Serial.printf("LoRaWan OTAA - set band is incorrect! \r\n");
return;
}
uint16_t maskBuff = 0x0002;
api.lorawan.mask.set(&maskBuff);
The supported regions are as follows:
- RAK_REGION_EU433 = 0
- RAK_REGION_CN470 = 1
- RAK_REGION_RU864 = 2
- RAK_REGION_IN865 = 3
- RAK_REGION_EU868 = 4
- RAK_REGION_US915 = 5
- RAK_REGION_AU915 = 6
- RAK_REGION_KR920 = 7
- RAK_REGION_AS923-1 = 8
- RAK_REGION_AS923-2 = 9
- RAK_REGION_AS923-3 = 10
Figure 1: Updating to US915 and setting up channel mask- The last step is to upload the code by clicking the Upload icon. Take note that you should select the right board and port.
The module should automatically go to BOOT mode when the firmware is uploaded via Arduino IDE. If BOOT mode is not initiated, you can manually send AT+BOOT command to start bootloader mode.
Figure 1: Uploading the code- You should now be able to view the terminal logs in the Serial Monitor of the Arduino IDE. There are times the COM port may be disconnected, preventing you from viewing of the terminal output immediately. In such cases, you can reconnect the module or try pressing the reset button to see the terminal output.
Figure 1: Output logs- You can also check on the LoRaWAN network server if your device has been successfully joined with the
join requestandjoin acceptlogs.
Standard OTAA mode requires the Device EUI, Application Key, and Application EUI, but in ChirpStack’s implementation, only the Device EUI and the Application Key are mandatory. The Application EUI is not required and not recorded in the Application tab. Nevertheless, you can reuse the Device EUI as the Application EUI during the configuration on the side of the node.
Upload ABP LoRaWAN Example to RAK11161
After successfully registering the module to the LoRaWAN Network Server as an ABP device, proceed with running the LoRaWAN ABP demo application example.
- Open the example code under RAK WisBlock RUI examples.
Figure 1: ABP LoRaWAN application example- In the example code, you need to modify the device address (DEVADDR), application session key (APPSKEY), and network session key (NWKSKEY). All these parameters should match the ones generated on the LoRaWAN network server.
Figure 1: Updating DEVEUI and APPKEY- This guide uses the EU868 regional band. There is no need to change the band in the example code. If the region you are in is different, you need to update the band in the code as well.
if(!(ret = api.lorawan.band.set(4))) // configure to EU868
{
Serial.printf("LoRaWan OTAA - set band is incorrect! \r\n");
return;
}
The supported regions are as follows:
- RAK_REGION_EU433 = 0
- RAK_REGION_CN470 = 1
- RAK_REGION_RU864 = 2
- RAK_REGION_IN865 = 3
- RAK_REGION_EU868 = 4
- RAK_REGION_US915 = 5
- RAK_REGION_AU915 = 6
- RAK_REGION_KR920 = 7
- RAK_REGION_AS923-1 = 8
- RAK_REGION_AS923-2 = 9
- RAK_REGION_AS923-3 = 10
In addition to that, if you are using US915 you also need to set up the channel mask (channels 8 to 15 are the most commonly used channels in the US915 band).
- The last step is to upload the code by clicking the Upload icon. Take note that you should select the right board and port.
The module should automatically go to BOOT mode when the firmware is uploaded via Arduino IDE. If BOOT mode is not initiated, you can manually send AT+BOOT command to start bootloader mode.
Figure 1: Uploading the code- The terminal logs should now be visible in the Serial Monitor of the Arduino IDE. If the COM port disconnects, the terminal output may not appear immediately. You can reconnect the module or try to press the reset button to see the terminal output.
Figure 1: Output logs- You can also check on the LoRaWAN network server
Live dataif your device can successfully send uplink packets.
Figure 1: TTN Live Data- On ABP, frame counters for both uplink and downlink need to be tracked by the device firmware. However, on RUI3 ABP, there is no tracking, and frame counts will go back to zero when the device resets. This will result in failures on uplinks and downlinks. To prevent this issue, enable the Resets frame counters option by following these steps.
Figure 1: General Settings- Click
Expandon Network Layer.
Figure 1: Expand Network Layer- Select
Advanced MAC settings.
Figure 1: Advance MAC settings- Check
Resets frame counters. With this enabled, all uplinks and downlinks will be successful even if the device resets/restarts.
Figure 1: Resets Frame CountersMore examples for the RAK11160 can be found in the RUI3-Best-Practices on Github.
