In this quickstart, you will learn how to register your Things Node with The Things Stack and program it with the Arduino software for activating with The Things Stack.
The Things Node is based on the SparkFun Pro Micro - 3.3V/8Mhz with an added Microchip LoRaWAN® module (RN2483 or RN2903). It features a temperature sensor, NXP’s digital accelerometer, light sensor, pushbutton, and RGB LED. All this is packaged in a matchbox-sized waterproof (IP54) casing with a 3 AAA battery compartment. The Things Node is compatible with the Arduino software (IDE).
Setting Up Arduino
Download the latest release of the Arduino Software (IDE) and install it on your operating system.
Start the Arduino Software (IDE).
The Things Network has written two Arduino libraries (The Things Network Arduino Library and The Things Node Arduino Library) for the Things Node. The Things Network library provides functions to communicate with The Things Stack (E.g. device activation, sending data, etc). The Things Node library helps you to configure the sensors and read sensor data from onboard sensors (E.g. configuring the onboard temperature sensor and reading the temperature).
In the Arduino IDE, select Sketch → Include Library → Manage Libraries… or Tools → Manage Libraries… from the menu bar.
In the Library Manager window, search for TheThingsNetwork.
Select TheThingsNetwork Arduino library from the search results.
Select the Install button.
When the installation finishes, again in the Library Manager window, search for TheThingsNode.
Select TheThingsNode Arduino library from the search results.
Select the Install button.
When the installation finishes, close the Library Manager by selecting the Close button.
Finally, you should add the SparkFun Pro Micro board package to the Arduino IDE. Select File → Preferences from the menu bar and paste the following URL into the Additional Board Manager URLs text box.
https://raw.githubusercontent.com/sparkfun/Arduino_Boards/main/IDE_Board_Manager/package_sparkfun_index.json
Select the OK button.
Open the Board Manager by selecting Tools → Board → Board Manager… from the menu bar.
Then open the Board Manager by clicking Tools → Board → Boards Manager… from the menu bar.
Search for sparkfun in the Board Manager. You should see the SparkFun AVR Boards package appear. Select the Install button.
Connecting The Things Node to a Computer
The Things Node can be connected to a computer using a micro-USB cable. First, you should open the enclosure to access the USB port on the back of The Things Node’s PCB.
Note:
USB is usually the easiest way to power The Things node, especially when you are programming it. It is acceptable to connect both batteries and a USB connector at the same time. The Things node can automatically select the best power source.Using a Phillips screwdriver remove both screws as shown in the following image.
Connect a micro-USB cable to the connector found between the battery compartment and the top side of the case. Then connect the other end of the micro-USB cable to your computer.
Note:
Some micro-USB cables might not fit the limited space between the battery compartment and the casing. Also make sure you use a cable that supports data, not just power. The one we ship with The Things Uno should work.Connect the other end of the USB cable to your computer.
In the Arduino IDE, select Tools → Boards → SparkFun AVR Boards → SparkFun Pro Micro from the menu bar.
Select Tools → Processor → ATmega32U4 (3.3V, 8MHz) from the menu bar.
Select Tools → Port and choose the correct serial port associated with your Things Node.
Getting the DevEUI and AppEUI
The sample sketch that can be found in the TheThingsNetwork Arduino library prints the DevEUI, AppEUI, and some other useful information when you need to register your Things Node with The Things Stack.
In the Arduino IDE, select File → Examples → TheThingsNode → DeviceInfo from the menu bar. The DeviceInfo sketch will open in a new window. The sample sketch should look something like this.
#include <TheThingsNetwork.h>
#define loraSerial Serial1
#define debugSerial Serial
// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan REPLACE_ME
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
void setup()
{
loraSerial.begin(57600);
debugSerial.begin(9600);
}
void loop()
{
debugSerial.println("Device Information");
debugSerial.println();
ttn.showStatus();
debugSerial.println();
debugSerial.println("Use the EUI to register the device for OTAA");
debugSerial.println("-------------------------------------------");
debugSerial.println();
delay(10000);
}
Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915 depending on the frequency plan of your Things Node and your country/region.
// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan REPLACE_ME
Note:
The Things Node supports only EU868 and US915 frequency plans.Select Sketch → Upload from the menu bar to upload the sketch. The Arduino IDE verifies your sketch again and uploads it to your Things Node.
Once uploaded, your sketch will immediately start to run but you cannot see any output unless you open the Arduino Serial Monitor. The Arduino Serial Monitor is a tool that can be used to print information passing through the serial port.
Select Tools → Serial Monitor from the menu bar to open the Serial Monitor.
Once open the Arduino Serial Monitor prints something similar to the following output.
Device Information
EUI: 0004A30B001BDFA4
Battery: 3294
AppEUI: 70B3D57EF0004C75
DevEUI: 0004A30B001BDFA4
Data Rate: 5
RX Delay 1: 1000
RX Delay 2: 2000
Use the EUI to register the device for OTAA
-------------------------------------------
Copy the Serial Monitor output into a text editor (E.g. Notepad) because you will need the AppEUI and DevEUI when you register your Things Node with The Things Stack.
Creating an Application
The Things Node (or any end device) first needs to be registered with an application to communicate with The Things Stack. To create a new application, follow the instructions on the Adding Applications page.
Registering The Things Node with The Things Stack
It’s time to register your Things Node with The Things Stack.
On the Applications page, select your application to view its Overview page.
Select + Add end device in the bottom-right of the page.
The Things Stack provides two options to register your end device:
- From the LoRaWAN Device Repository
- Manually
The From the LoRaWAN Device Repository option provides only the OTAA activation method and the Manually option provides both OTAA and ABP activation methods. In this tutorial, we only look at the first option, From the LoRaWAN Device Repository which is the easiest way to register your Things Node with The Things Stack.
On the Register end device page, select the From the LoRaWAN Device Repository tab, if not already selected by default.
Under Select the end device, select the following mandatory fields.
- Brand -
The Things Products
- Model –
The Things Node
- Hardware Ver. –
1.0
- Firmware Ver. –
1.0
- Profile (Region) – Choose
EU_863_870
orUS_902_928
to match with your board.
Under the Enter registration data, select/fill the following mandatory fields.
- Frequency plan – Select
Europe 863-870 MHz (SF9 for RX2 - recommended)
for EU_863_870 orUnited States 902-928 MHz, FSB2 (used by TTN)
for US_902_928. - AppEUI – Copy the AppEUI from the output printed by the DeviceInfo sketch.
- DevEUI – Copy the DevEUI from the output printed by the DeviceInfo sketch.
- AppKey – Select Generate button to generate an AppKey.
- End device ID – Give your device a unique human-readable identifier.
Select the Register end device button.
Once registered, you will be redirected to the overview page of the newly registered Things Node, where you can find the generated AppKey which we’ll need next.
Payload Formatter
The Things Node supports different types of payload formatters. However, for this quickstart you can use the payload formatter which we have provided through our Device Repository.
Click on the Payload formatters tab, then click on the Uplink tab.
Select Use Device Repository Formatters from the Formatter type drop-down box.
Click on the Save changes button.
Activating The Things Node - OTAA
To activate the Things Node using Over-the-air-activation (OTAA), you must enter some configuration settings from The Things Stack.
In the Arduino IDE, select File → Examples → TheThingsNode → Basic from the menu bar. The Basic.ino sketch will open in a new window.
Replace the lines following the comment Set your AppEUI and AppKey. These keys can be found in your Things Node’s overview page under the Activation information.
// Set your AppEUI and AppKey
const char *appEui = "0000000000000000";
const char *appKey = "00000000000000000000000000000000";
Replace REPLACE_ME with TTN_FP_EU868
or TTN_FP_US915
depending on the frequency plan of your Things Node and your country/region.
// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan TTN_FP_EU868
Select Sketch → Upload from the menu bar to upload the sketch.
Once uploaded go to the Live data section/tab of your application or The Things Node. You should be able to see the decoded payload of each event (setup, interval, motion, button).
You have now completed the quickstart and are able to activate The Things Node, send messages to an application, and decode them from the server side to get meaningful data. Go build something!