[TOC]
This guide explains how the Standalone LoraWAN Gateway works. We will use MQTT to subscribe uplink messages from TTN stack. Once the messages from the registered devices arrive to the LNS, they are being published as MQTT messages so we can process them from Node-RED. The environmental data is stored in the influxdb databases, and then visualized through Grafana.
We have 7 services defined in the docker compose file:
udp-packet-forwarder
interacts with the LoRa chip to receive and transfer LoRa packetsstack
is a TTN stack service which depends onredis
andpostgres
service. This service enables connectivity, management, and monitoring of devices, gateways and end-user applicationsredis
is the main data store for the Network Server, Application Server and Join Server, and it is also used by Identity Server and event system.postgres
is another databased used bystack
node-red
service contains a default flow which subscribe uplink data from TTN stack by MQTT protocol and stores the data into ainfluxdb
database, whose name is sensors;influxdb
service provide a database whichnode-red
will usegrafana
service uses the influxdb as a data resource, and visualize the data.
The included run.sh
script takes care of tweaking the dcoker-compose.yml
file to change the IP of the host and bring up all the service.
$ ./run.sh
After running it wait a few seconds for the Stack web UI to become alive and click on the provided link to access the web UI. The default User ID and Password is admin
and changeme
.
After you login, you need to create your a gateway first using the GATEWAY_EUI provided by the run.sh
script, see the 2.1 Create Gateway
section below.
Navigate to the web-interface of Node-RED
(use the link provided by the run.sh
script) and you should be able to see the default flow. It's not ready to work for now, we will create an application in TTS first, and then come back and fill out some important information to make it work.
Open grafana
(use the link provided by the run.sh
script). The default Username and Password is admin
and changeme
. When loged in, there will be a default data resource.
As a side note, we can also access influxdb
container with the following commands. The default username and password for the user in the influxdb container are admin
and changeme
. Then we will found there is a sensors
databases.
You need to add your gateway to TTS first. Go to the Gateway configuration page, enter the general ID, Gateway EUI, Gateway server address, and also the frequency plan. If you use the default docker compose file, your gateway EUI can be acquired by running the following command in your host:
docker exec -it udp-packet-forwarder ./get_eui.sh
The gateway server address is the one you defined in the docker compose file. Make sure you choose the right frequency plan.
after the gateway is created in TTS, you should be able to see the gateway is online in the gateway detail page:
Now, as we mentioned above, we need to create an application in TTS.
Select Write downlink application traffic
and Read application traffic (uplink and downlink)
at least. The two rights is needed by MQTT.
Copy the API key, we will use it on NodeRED flow. Please note that you must copy the key and store it somewhere safe. If you forget to save it, you won't be able to see it again, unless you create a new API keys and copy it.
Now, the TTS side's configuration is about to finish, we need to add end-devices to the application so that we can start to receive uplink data sent by the end-devices on the gateway. But even before that, we need prepare the end device. The end device we used is a WisBlock kit with the RAK1901 sensor that reports temperature and humidity. You can find more details in RAKwireless's official documentation. The Arduino code rak1901.ino is provided, you can copy paste the code, and then upload to the board. Make sure to change the device EUI, the App EUI, and the App key.
Now we need to go back to the TTS, under the application page, add your first end-device:
switch to manually mode, and then enter the following higlighted section, make sure the DevEUI, AppEUI, AppKey match what you defined in the Arduino code:
After the end-device is registered, you should be able to see the end-device is online, and also the uplink data sent from the end-device:
to make use of the CayenneLPP, you need to go to the end-device's page, and then in the Payload formatters page, switch the default ulplink formatter type to CayenneLPP:
now you should be able to see the converted live-data:
Open mqtt-broker
node and paste the API keys we saved before to the Password. The Username is the id of application we created before in TTS's application page.
Open influxdb
node and modify Username and Password. If username is admin
and Pasword is changeme
, you needn't to change it.
The format of uplink data of ttn stack is v3/{application_id}/devices/{device_id}/up
. Here we user +
to subscribe all devices under application app01
. If you only want to subscribe one device, you can change +
to the id of specific device.
If all has been done correctly, after you click Deploy button, you should be able to find status of mqtt client is connected
:
and your
Now, the temperature and humidity data is monitoring by the end-devices, and the data is upload to the TTS and then saved to the influxdb databases. Now we are going to visulize the data.
Open Grafana's web interface and then create a new dasbboard:
the "measurement" will be something like "eui-xxxxxxxx", and you can Select either/both "temperature_1" or "relatively_humidity_2" to display. If you want to display temperature and relatively_humidity on the same panel, you can create another query. The final result should be somthing like the following graph:
This project is licensed under MIT license.