LoRaWAN, which stands for Long Range Wide Area Network, is a low-power, wide-area network (LPWAN) protocol designed for long-range communication between low-power devices. It enables long-range wireless communication with low data rates and low power consumption, making it suitable for Internet of Things (IoT) applications. LoRaWAN consists of end-devices, gateways, and a network server. The end-devices are low-power devices that collect and transmit data, the gateways receive the data from end-devices and forward it to the network server, and the network server manages the network and processes the data.
In this project we will setup an end-device to monitor temperature and atmospheric pressure. To measure temperature and atmospheric pressure we will use the BMP280 digital barometric pressure and temperature sensor manufactured by Bosch Sensortec. The BMP280 combines high accuracy with low power consumption, so is ideal for remote environmental monitoring. Choose a breakout board with an I²C interface, such as the Seeed Studio device in the photograph below.
For sending data from our monitoring station (end-device) we will use the M5 Stack Unit LoRaWAN868 module (photograph below). This LoRaWAN module communicates with the Arduino Uno via universal asynchronous receiver-transmitter (UART). The UART interface is also used to program the Arduino Uno, so do not connect the LoRaWAN module to the Arduino Uno until the latter has been programmed.
N.B. The LoRaWAN module operates in the 868 MHz frequency band. The 868 MHz frequency band is supported in the following countries: Albania/Andorra/Armenia/Austria/Bahrain/Bangladesh/Belarus/Belgium/Myanmar/Bosnia and Herzegovina/Brunei Darussalam/Bulgaria/Cambodia/Cambodia/Croatia/Cyprus/Denmark/Egypt/Estonia/ Finland/France/Germany/Germany Guatemala/Hungary/Iceland/Iran/Ireland/Italy/Laos/Latvia/Lebanon/Liechtenstein/Lithuania/Luxembourg/Macedonia, the former Federal Republic of Yugoslavia/Malta/Moldova/Montenegro/Morocco/ Netherlands/Netherlands/New Zealand/Nigeria/Norway/Oman/Pakistan/Poland/Portugal/Qatar/Romania/Saudi Arabia/Serbia/Singapore/Slovenia/South Africa/Spain/Sweden/Switzerland/Tunisia/Turkey/Ukraine/UAE/UK/ Vietnam.
Our project involves the following steps:
- Install a Gateway, if there isn't one within range of our end-device.
- Create a data processing application on a LoRaWAN network server.
- Program the Arduino Uno.
- Connect the Arduino Uno to the sensor breakout board and LoRaWAN module.
- Create a data visualization dashboard.
Some familiarity with the visual programming language XOD is assumed. If you haven't used XOD before I recommend taking a look at the following resources:1. Setup LoRaWAN Gateway (if needed)
If your monitoring station (LoRaWAN end-device) isn't within range of an existing gateway, you will need to setup your own gateway. The Things Indoor Gateway is a good low-cost device for prototyping; follow the link for retailers and setup instructions.
The Things Stack Community Edition (CE) is the open-source version of The Things Stack, which is an enterprise-grade LoRaWAN network server developed by The Things Industries (TTI). The Things Stack CE provides a free and accessible platform for individuals, communities, and organizations to deploy and manage their own LoRaWAN networks. You can sign up for the Things Stack CE here: https://www.thethingsnetwork.org/get-started
Once you have an account, you can create an application by following these steps:
2.1 Create application
Click on the Create application button:
Give your application an ID, name and description (optional):
Once created your application will appear like this:
2.2 Select payload formatter
The payload formatter enables the application server to understand and interpret the data sent by the end-devices, facilitating further processing, storage, analysis, or visualization of the received information. We use CayenneLPP.
From the menu on the left panel choose Payload formatters > Uplink and then select CayenneLPP from the dropdown list. Click the Save changes button.
2.3 Register the end device.
Specify End device type.
- For Input method select Enter end device specifics manually.
- For Frequency plan choose "Europe 863-870 MHz (SF9 for RX2 - recommended)"
- For LoRaWAN version select "LoRaWAN Specification 1.0.4"
- For Regional Parameters version select "RP002 Regional Parameters 1.0.3"
Scroll down for Provisioning information:
Make a note of the JoinEUI, DevEUI and AppKey. We will need these identifiers when we program the Arduino Uno.
We will use XOD, a visual programming language.
3.1 Install required libraries
In addition to the core XOD libraries, we also need the following user-contributed libraries:
- wayland/bmp280-barometer - BMP280 barometric pressure and temperature sensor.
- wayland/cayenne-lpp - Cayenne Low Power Payload with Extended Data Types. CayenneLPP format is an efficient way to send sensor data over low bit rate connection, such as LoRa.
- wayland/m5stack-unit-lorawan - M5Stack LoRa868 module.
To install a library use the File → Add Library menu item in the XOD IDE. See Using libraries for more information.
3.2 Start a new project in the XOD IDE
From the File menu select New Project...
3.3 Configure LoRaWAN module
- On a blank patch add the following nodes: xod/uart/uart-0 and wayland/m5stack-unit-lorawan/lorawan868-setup.
- On the uart-0 node set BAUD to
115200and set INIT to
- Connect the UART ports of the two nodes.
- Connect DONE output of uart-0 to the Init input of lorawan868-setup.
- Assign DevEUI (see section 2.3) to the D_EUI input of lorawan868-setup.
- Assign AppKey (see section 2.3) to the A_KEY input of lorawan868-setup.
- Set J_EUI (JoinEUI) to
00 00 00 00 00 00 00 00.
- Set Mode input of lorawan868-setup to
- Set Class input of lorawan868-setup to
- Add a xod/patch-nodes/to-bus node, label it
LoRaand connect it to the DEV output of lorawan868-setup.
3.4 Configure barometer/thermometer
- Add the following nodes: wayland/bmp280-barometer/barometer-thermometer and xod/core/clock.
- Use the default settings on the barometer-thermometer for I2C, ADDR, MODE, OST, OSP, FILT and STDBY. Check that INIT is set to
- Connect the clock TICK output to the UPD input of barometer-thermometer.
- Set the tick interval (IVAL) of the clock to
30seconds. A short interval has been chosen for testing; in normal use the interval would be much longer (many minutes to hours).
3.5 Create a low power payload (LPP)
We need to create a LPP for packaging our data for transmission to the LoRaWAN gateway. The size of the payload is determined by the type of data we are collecting. Each sensor in the payload is prefixed by two bytes:
- Data Channel: Uniquely identifies each sensor in the device across frames
- Data Type: Identifies the data type in the frame, eg. “temperature”.
To find out the number of bytes required to store a particular data type, please see this list. The temperature and barometric pressure data types both have a size of two bytes. Therefore, the size of the total payload will be eight bytes (2 prefix bytes and 2 data bytes for each sensor).
- Add a wayland/cayenne-lpp/lpp node.
- Set the Size of lpp to
- Add a xod/patch-nodes/to-bus node for the output from lpp and label it
3.6 Add temperature and barometric pressure data to LPP
We now need to add our temperature and barometric pressure measurements to the LPP.
- Add the following nodes: wayland/cayenne-lpp/add-temperature, wayland/cayenne-lpp/add-barometric-pressure and xod/core/divide.
- Connect the LPP inputs of add-temperature and add-barometric-pressure to the output of lpp.
- Each sensor in the LPP must have be uniquely identifiable, so set CHL of add-temperature and add-barometric-pressure to
- The TEMP output of barometer-thermometer can be connected directly to the Temp input of add-temperature.
- The PRESS (Atmospheric pressure in Pascal) output of barometer-thermometer should be divided by 100 to convert it to our preferred units of hectopascals, before being fed into the BP input of add-barometric-pressure.
- The DONE output of barometer-thermometer should be connected to the UPD input of add-temperature.
- The Done output of add-temperature should be connected to the UPD input of add-barometric-pressure.
3.7 Send LPP
The final step is to send the LPP and then empty the payload buffer ready for the next pair of measurements.
- Add the following nodes: wayland/m5stack-unit-lorawan/send-lpp,wayland/cayenne-lpp/reset and two xod/patch-nodes/from-bus nodes.
- Label one of the from-bus nodes
LoRaand connect it to the DEV input of send-lpp.
- Label the other from-bus node
LPPand connect it to the LPP input of reset.
- Set CFM (confirmation) on send-lpp to
Truefor the purposes of testing. However, in normal use, confirmation of uplinks should be avoided. Please see sending responses from your application to your node downlink.
- Trials (attempts to send message) on send-lpp can remain at the default value of
- LPP on send-lpp should be connected to the output of the lpp node.
- UPD on send-lpp should be linked to Done on add-barometric-pressure.
- UPD on reset should be connected to Done on send-lpp.
3.8 Upload project to Arduino
Connect the Arduino to your computer and then from the Deploy menu of the XOD IDE select Upload to Arduino...
Check that the correct board model and serial port are selected before clicking the Upload button. After successfully uploading the project, the Arduino can be disconnected from your computer.4. Connect the Arduino Uno to the sensor breakout board and LoRaWAN module
Make the following connections between the BMP280 breakout board and the Arduino Uno:
- Connect Vin on the BMP280 breakout to the 5V power supply of the Arduino Uno.
- Connect GND to GND (common ground).
- Connect the SCL pin to A5 (I²C clock pin) on the Arduino Uno.
- Connect the SDA pin to A4 (I²C data pin) on the Arduino Uno.
The LoRaWAN module is wired to the Arduino Uno as follows:
- Connect 5V on the LoRaWAN module to the 5V power supply of the Arduino Uno.
- Connect GND to GND (common ground).
- Connect TXD to RX (digital pin 0 on the Arduino Uno).
- Connect RXD to TX (digital pin 1 on the Arduino Uno).
Power up your Arduino Uno and then return to The Things Stack console to check that data are being received. A summary appears on the Overview tab of your End device:
Switch to the Live data tab for more detailed information on the messages received:
The Things Stack facilitates the use of a third party application server for visualizing our data. This is done by means of a webhook.
5.1 Setup webhook
Go to your application on The Things Stack console and navigate to Integrations → Webhooks. Select Cayenne from the list of templates.
Give your webhook a name and then click Create Cayenne webhook.
That is all we need to do from The Things Stack console.
5.2 Create dashboard on Cayenne
You first need to register for an account with Cayenne (myDevices) by completing this form. You can then sign in and start creating our dashboard.
You will be prompted to select a device for our project:
You will be presented with a list of networks. Select The Things Network:
From The Things Network submenu, choose Cayenne LPP:
You will be prompted to enter some information for your project:
Choose any name you like. DevEUI is provided by The Things Stack (see section 2.3 above). For Activation Mode select
Already Registered. After clicking the Add device button, a data dashboard will appear:
In addition to temperature and barometric pressure, we also have two other measurements: RSSI and SNR.
- RSSI stands for Received Signal Strength Indicator. It is a measurement of the signal strength of the received LoRa radio signal. A higher RSSI value indicates a stronger signal, implying a shorter distance or better signal quality between the transmitting device (LoRa node) and the receiving device (LoRa gateway or receiver).
- SNR is the signal to noise ratio. It is a measure of the strength of the desired signal relative to the background noise present in the received signal.
The appearance of the four widgets can be modified. Click on the cog symbol in the top right corner of the widget to see options:
From the Choose Widget list box, select Gauge. Notice that you can set colours for different temperature ranges.
Do the same for atmospheric pressure:
You can use your mouse to resize and arrange your widgets on the dashboard:
To view a line graph of any of the measurements, click on the chart icon in the top right corner of the widget:
Switch to the Data tab to view the data in a table:
This project demonstrates how devices for remote monitoring over LoRaWAN can be rapidly prototyped using The Things Network, Cayenne and XOD.