Storing Data locally in Raspberry-Pi with Lorawan Gateway

Hi,

I have RAK 5146 Lorawan Gateway, which is connected to Raspberry-pi[4B] using Pi-Hat2013. Until now, I have successfully sent the sensor data to the Things Network with the help of RAK 3172 Lora Module and RAK 5146 Lorawan Gateway. Also, I can save to data in influx DB with the help of Node-red MQTT protocol [Which is running in Raspberry-pi] and TTN MQTT as Broker. But this is achieved in case when data is received at TTN. I want to store the data locally in raspberry-pi before sending it to The Things Network, so when the internet is not available, I am sure that my data is not lost and also, I want to prepare the dashboard locally. So, is there any way, that the data packets which is received by Lorawan gateway, I can collect the data in influx DB and then send it to TTN.

Can anyone help me?

Thanks in advance!!

There are a number of ways to achieve what you need.

The simplest one (and more LoRaWAN compliant) is to install a LoRaWAN Network Server (LNS) locally on the Raspberry Pi. ChirpStack or The Things Stack are the two most popular open source options. This way you will have a complete private network and stop using TTN (not sure if that’s what you want). You will have to register the device on the local LNS and connect you NodeRED to the local MQTT instead of TTN’s MQTT.

A more advanced options is to use ChirpStack Concentratord (Introduction - ChirpStack open-source LoRaWAN® Network Server documentation). As you can see this component can rely the messages to remote servers using MQTT Forwarder and also subscribe to local data via ZeroMQ.

Another option (albeit more “fishy”) are to use ChirpStack multiplexer to redirect to multiple LNS. This is kind of dangerouse if using downlinks or OTAA. Not recommended.

Either way there is a bit of research to do on your side to see what option suits you better depending on what ytou want to do.

Hi @xoseperez,

Thank you so much for suggesting different ways.
I want to known, can I use Rak5146 UART communication, which further I can connect to Raspberry-Pi UART lines and can get the data packect into the Raspberry-Pi simultaneously.

Thanks in advance!!!

The UART bus in the RAK5146 is connected to the GPS, not the SX1303 LoRa chip. So you won’t get the packets only the NMEA sentences from the GPS.
You could get the packets directly using the SPI interface (or USB interface depending on the model) but you will have to work on the code yourself, starting with the HAL (GitHub - Lora-net/sx1302_hal: SX1302/SX1303 Hardware Abstraction Layer and Tools (packet forwarder...)).

Hi @xoseperez.

Thank you so much for the feedback!!

As, I am new to this, I am facing problems in clearing my concepts, it would be nice if you could help me in clearing that?

For getting data packets directly to raspberry pi through SPI, how can I do that? Right now I am using this global_conf.json file[ global_conf.json.sx1257.EU868] in this SPI is enable. So, where and How should I write the code to get the data packets in raspberry pi. I have connected RAK5146 Lora gateway through RAK2003 Pi-HAT with Raspberry-Pi.

Thanks in Advance!!

I recommend you not to write your own packet forwarder unless you are a hardcore programmer. Best option is still to have the LNS running locally and get the info from the LNS via MQTT also locally.

Hi @xoseperez ,

Thank you so much!!

Is it possible to provide, any latest link where I can follow and download Things Stack Network locally in Raspberry-Pi.

Thanks in Advance!!!

Hi @xoseperez ,

I found your Git repository for the same(GitHub - xoseperez/standalone-lorawan-gateway-balena: Deploys the The Things Stack LoRaWAN Network Server Open Source Edition, BasicStation and Backend tools using Balena.). Is this the correct one?

Thanks in advance!!

This is a Balena project that has everything built-in (including NodeRED, Grafana and a timeseries database). It’s not the only way but if you want something quick to start with this one will surely help.

Hi @xoseperez ,

I tried using balena, when I calling things stack with raspberry pi ip address, Things stack login page is coming, but when i enter user name [ admin ] and Pass[ changeme ] I am getting error. Also, I can’t excess the raspberry pi via ssh.

Thanks in advance!!!

Hi @xoseperez ,

Sorry for the trouble!
I tried clearing cache and History and also I tried opening in Incognito Tab, I can only see the Things Stack Login page. After entering username and Password It is showing error. Can you please help me?

Thnaks in Advance!!!

Hi
The error happens when the IP/Domain of the The Things Stack server does not match. Make sure you set the TTS_DOMAIN variable correctly in the stack service to the IP of your machine. The service should then restart and create the right credentials for that IP and you should be able to login with the default username/password.

Hi @xoseperez ,

Sorry, for the trouble again!

With Balena it works perfectly. But I want to install things stack withou balena, So i referred the doucment [Configuration | The Things Stack for LoRaWAN], I successfully connected with the IP address of my raspberry-pi. But the problem is, When, I enter the user name and password, It is reloading the same page, neither it is showing wrong credentials nor I can open the console. I can see the client error in linux terminal, below I am attaching the photo of the same. Can you please help me with this?

Thanks in Advance!!!

Yes, there are some extra few steps to make it work. That’s why I put together a new docker image as a wrap up for the TTS official image that includes configuration and certificate auto-generation. You can find it here: GitHub - xoseperez/the-things-stack-docker: The Things Stack LoRaWAN Network Server (Open Source Edition) on a Raspberry Pi using docker . It is the same image that uses the balena project you tested before. In the end, Balena is a device and fleet manager that runs services as docker containers. You can still run them without Balena…
Make sure, again, to define the TTS_DOMAIN variable to the right IP.

@pjariwala On a separate note, try this on a new SD card with fresh RPi OS.

Aim: To have your own Gateway Packet Forwarder, Chirpstack LoRa Network Server (LNS) and Application Server including MQTT broker , data storage native on Raspberry Pi+RAK5146 HAT.

  1. Follow the instructions on the RAK link - Quick Start Guide for Raspberry Pi and RAK LPWAN Concentrators | RAKwireless Documentation Center

  2. Execute “gateway-config” on the commandline and select Chirpstack instead of TTN and also select 127.0.0.1 as LNS Server. (i.e. 127.0.0.1 on global.conf)

  3. Add your devices on the application server RPI-IPADDRESS:8080, Join mode ABP or OTAA. Add decode codec suitable for the devices you are using. Make sure you are getting packets on the Device Data tab.

  4. Configure Node-RED MQTT node to spit out human readable/JSON format of incoming DATA component. Configure Node-RED file nodes to store data locally. Rakstar Enjoy :checkered_flag:

In this way you need not go out of Raspberry Pi (to external LoRaWAN Servers for example). All the tasks that you mentioned such as receiving LoRaWAN packets in the concentrator, forwarding it to localhost (127.0.0.1) LNS, decoding DATA packets on Node-RED using local MQTT broker, storing data in csv files locally using Node-RED file nodes can be done on the Raspberri Pi itself.

Thanks to RAKwireless, Chirstack (Brocaar), Node-RED( Nick O’Leary), The Things Network, Mobilefish, Steve Cope, Anh Quan Tong and many more YouTubers for their contribution on the LoRa and LoRaWAN platform and IoT.

Hi @xoseperez ,

I tried your version also, but the same error is coming which I mentioned before, this time I had define TTS_DOmain to Rspberry pi IP address. In addition to this, one more error is coming, which I have attached below in the picture. Can you, please help me?

Thanks in Advance!!!

Hi @Cloudmiracle

Thanks for the feedback!.

I have one question, So, first I have to send the lora packets to the Chirpstack public server and, then I have to install Node-Red, into the Raspberry pi and then I will send data to infulx Db and store it in Raspberry pi, Is it like that, or I am understanding it in a wrong way?

Thyanks in Advance!!!

@pjariwala

I think you forgot to attach the picture…

Hi @xoseperez ,

I am so sorry for that.

Thanks!!!

Well, have you defined any LNS or CUPS configuration in your docker-compose.yml file?
I suggest you to read the section in the TTS docker image that talks about pairing it with a basicstation service: GitHub - xoseperez/the-things-stack-docker: The Things Stack LoRaWAN Network Server (Open Source Edition) on a Raspberry Pi using docker and GitHub - xoseperez/the-things-stack-docker: The Things Stack LoRaWAN Network Server (Open Source Edition) on a Raspberry Pi using docker .
Hints:

  • Set the TC_TRUST and TC_KEY in your basicstation service once you have your gateway created in TTS
  • Use TLS_SNI=false in your basicstation service to avoid certificate checking (will fail agains IP-signed certificates).