It is possible to implement a private LORAWAN Network to connect Lora Nodes via gateways to a LoraWAN server and have the data collected from these nodes saved to a database or other storage medium. I will attempt to outline the steps required in summary. While this is meant to serve as a sort of guide, I will be referring to other articles which have detailed step by step instructions for implementing some of the functional units while adding a few pointers of my own. This article would guide the integration of the system as a whole.
In order to implement a private LoRaWAN Network, the following are required.
-
LoRa Nodes (The Thing in the Internet of Things)
-
At least one LoRaWAN Gateway/Packet Forwarder (An Access Point for the LoRa Nodes)
-
LoRaWAN Network Server.
I use the opensource LoRa Server project by @brocaar available here https://www.loraserver.io/ , and it provides the following:
a. LoRa Gateway Bridge: A service which abstracts the packet-forwarder UDP protocol into JSON over MQTT.
b. LoRa Server: A LoRaWAN Network Server, responsible for de-duplication and handling of received uplink frames received by the gateway(s), handling of the LoRaWAN mac-layer and scheduling of downlink data transmissions.
c. LoRa App Server: A LoRaWAN application-server, responsible for the device “inventory” part of a LoRaWAN infrastructure, handling of join-request and the handling and encryption of application payloads.
-
Node-RED: A simple programming tool for connecting hardware devices, APIs and online services.
The situation described already has LoRa Nodes and a Gateway so I will begin with the LoRaWAN Network Server. A Raspberry Pi or other single board computer running raspbian, armbian or other debian strain including Ubuntu, is required.
STEP 1. The LoRa Gateway Bridge requires an MQTT broker. Follow the detailed instructions here https://www.loraserver.io/lora-gateway-bridge/install/requirements/ to install Mosquitto MQTT broker.
STEP 2. Follow the detailed instructions here https://www.loraserver.io/lora-gateway-bridge/install/debian/ to install the LoRa Gateway Bridge and confirm it is running.
STEP 3. Install all requirements for the Lora Server. These include MQTT, REDIS Server and PostgreSQL. Detailed instructions are here. https://www.loraserver.io/loraserver/install/requirements/ . NOTE that you already installed an MQTT broker on the same machine so no need to install another.
STEP 4. Follow the detailed instructions here https://www.loraserver.io/loraserver/install/debian/ to install the LoRa Server and confirm it is running. You may want to change a few parameters but from my experience, default settings work perfectly if all components are installed on the same machine.
STEP 5. The requirements for the Lora App Server should be installed following the instructions here https://www.loraserver.io/lora-app-server/install/requirements/ . However, you will notice that all required services (MQTT, REDIS Server and PostgreSQL) have been installed in the previous steps so all you need do is to enable the pg_trgm (trigram) extension in postgreSQL as described in the link above.
STEP 6. Install the Lora App Server by following the instructions here https://www.loraserver.io/lora-app-server/install/debian/ . Basic configuration works out of the box where all LoRaWAN Server Components are installed on the same machine. Also remember to create self-signed certificates for the webserver and fill in the correct locations of these files in the configuration file. At this point, you should have a fully functional LoRaWAN Server. To confirm this, login to the LoRa App Server WEB UI by navigating to https://:8080/. Username is admin and Password is admin. Remember to change them.
STEP 7. When logged in, create a network server (basically enter the details of your Lora server installed in STEP 4), add an organization, create device and service profiles and add your gateway(s). I recommend creating at least two device profiles, one for Activation by Personalization (ABP) and Over the Air Activation (OTAA). Please note that the LoRa server IP address on your gateway software (identified as TTN SERVER) on most single channel gateways / packet forwarder configurations should be set to the IP address of this server. After this configuration, do not power up your gateway until they have been created in the Lora App Server. If they are powered on before creation in the app server and are automatically detected by the Lora Server, you will see errors when you try to add them later on the Lora App Server.
STEP 8. Create an application by adding the details of the application under an organization.
STEP 9. Create each of your nodes as devices under the application you just created. This ensures the data collected from these nodes are published under the application. The devices will be configured based on the selected device profiles which you should have created previously. The server can provide both ABP and OTAA authentication methods .
STEP 10. Install Node-Red. Node-Red is usually preinstalled in Raspbian. However it may be outdated and it is recommended to update it. Configure Node-RED to start on boot using the command
sudo systemctl enable nodered.service
If running debian/ubuntu, follow the commands here https://nodered.org/docs/getting-started/installation to install. Also remember to configure node-red to autostart on boot.
STEP 11. With node-red installed, connect to node-red Web UI by navigating to http://:1880/. Once logged in, select and drag the “mqtt in” node from inputs on the left column, into your flow. Configure it to connect to your MQTT broker and subscribe to the application topic as described here https://www.loraserver.io/lora-app-server/integrate/data/ . The first application is usually published as 1. If unsure, first subscribe to application/#
and connect the output of “mqtt in” to a “json” node and then to a “debug” node to see the output in the debug tab. If the application ID is confirmed as 1 (for example), subscribe to application/1/node/+/rx
to receive all data from all nodes configured in the application. At this point, details of any data transmitted by your nodes should appear in the debug tab. This is the full message payload published by the LoRa App Server, formatted as json and would look like this.
{"applicationID":"1","applicationName":"smart-nodes","deviceName":"alpha-monitor","devEUI":"1234567887654321","rxInfo":[{"mac":"30aea4ffff5614e8","rssi":-86,"loRaSNR":9,"name":"esp32-demo-gateway","latitude":11.123456,"longitude":12.123456,"altitude":453}],"txInfo":{"frequency":868099975,"dataRate":{"modulation":"LORA","bandwidth":125,"spreadFactor":7},"adr":true,"codeRate":"4/5"},"fCnt":784,"fPort":1,"data":"RIwPQWWe7kCFAAMAYgAzUH1PAQAB"}
The information from your nodes is stored in the object (“data”:“RIwPQWWe7kCFAAMAYgAzUH1PAQAB”) and is Base64 encoded.
STEP 12. Add a javascript function node to the flow after the json node. The json node converts json formatted strings to javascript objects. Open the javascript function node and enter the following to convert the data from Base64.
//Decode data from transmission into variables var newMsg = { payload: msg.payload.length }; newMsg.payload = new Buffer(msg.payload.data, 'base64'); return newMsg;
Remove the “debug” node previously connected to the output of the "json: node and connect it to the output of the “function” node. Deploy the changes and subsequent data sent by your nodes will be displayed decoded in the debug tab.
STEP 13. To store the data, you can chose to write them to a file or save to a wide choice of databases. To write to a file, drag the “file” output node from the storage section of the list of nodes on the left column to the flow. Connect the file node to the output of the “function” node. Configure the name of the file you want the data saved to and select the options as needed. Ensure you select “Append to file as the action”. Deploy your changes.
At this point all the data received from your nodes will be saved to a file and you can download the file at any time. If you are adventurous, you can configure the function node to format your data further before storing to file.
I hope this helps.