On this tutorial I would like to show how to create a private LoRaWAN network on a Raspberry Pi 4 using balena. To demonstrate how it works i'm going to connect the new Seeed Studio SenseCAP S2101 (Temperature and Humidity) and SenseCAP S2104 (Temperature and Soil Moisture). We are going to use new services such as NodeRED, InfluxDB and Grafana to visualize locally all the data generated by these sensors.
On previous projects I shared how to deploy your own private LoRaWAN network. The main difference is that on this project we added a LoRa concentrator (Seeed WM1302) on the Raspberry Pi to provide coverage from the same device that generates the LoRaWAN Network Server and added extra services to visualize data received.
Go to balenaHub and deploy the `Standalone LoRaWAN Gateway` application or just `Deploy with balena` from the Application Github Repository.
Once deployed on a balenaCloud fleet, Add a new device.
Download the balenaOS image with your WiFi credentials and flash your SD card with balenaEtcher.
Power up your Raspberry Pi with the SD card and you should see something like this.
Now copy your local IP address and go to Device Variables. Override the `TTS_DOMAIN` variable with your local IP address.
Change the `MODEL` to `SX1302` if you are using the Seeed Studio WM1302.
Connect your gatewayType `https://<your local IP address>` and accept the risk.
To log in add the userID `admin` and password `changeme`.
Click `Register a gateway`.
Copy from the balenaCloud device dashboard the `EUI` that appears as a TAG. Paste it here.
Once the gateway is registered successfully, go to `API keys`.
Select the API key as a `Link as Gateway to a Gateway Server for traffic exchange`. And copy the API key generated.
Go to balenaCloud to the Device Variables section and modify the variable `TC_KEY`.
At that moment, the gateway should appear as Connected and the logs on balenaCloud should say that the `Concentrator started` successfully.
Install the Seeed Studio mobile application
As we are going to use the Seeed Studio SenseCAP S2101 and S2104, it's time to install the SenseCAP mate Application.
And configure the devices. On my side I made the `AppEUI` and `DevEUI` the same to simplify the copy and paste on the Settings during the `Setup` process.
Register the End Device on The Things Stack
Go to The Things Stack main menu. And click `Create an Application`.
Click `Add application`.
And then click `Add end device`. Select the SenseCAP brand and the S2101 and S2104
Use the credentials from the SenseCAP Mate App that we changed.
Once successfully created, you will be able to see the End Device. Push the button of the device to force a `join` message.
On the gateway `Live Data` section you should be able to see the `join` message from the End device and the first uplink/downlink messages.
On the End Device `Live Data` section you should be able to see the messages decoded as well.
NodeRED is accessible using `http://<your local IP address>:1880`. Log in using `balena` as username and password.
Install InfluxDB nodes if they are not installed yet.
This is the flow I created to capture the data from The Things Stack and store it on InfluxDB (later we will visualize it on Grafana).
To enable the MQTT node, go back to The Things Stack Application and click on `Integrations` and MQTT. Copy the username and generate the password.
On the MQTT block create as a server using the `stack` container to the 1883 port. The topic I used is `v3/+/devices/+/up`.
Go to Security and add the MQTT credentials from The Things Stack.
The function node I hacked some code to get `temperature` and `humidity` or `soil moisture`.
Configure InfluxDB
To connect the `InfluxDB out` node you will need to create the database on the influxdb container on balenaCloud.
Once the data is stored properly on InfluxDB, you can visualize it on Grafana.
Access to your Grafana service using `http://<your local IP address>:3000`and create your dashboard.
Feel free to add your comments here and confirm if this works for you. Any question feel free to write us on https://forums.balena.io.
Comments