Cytron Technologies
Giờ làm việc: 8:00 - 17:00
Thứ 2 - Thứ 6 (trừ ngày lễ)
Hotline 0362917357
Disclaimer:
This guide is provided for information and as it is. Cytron Technologies will not be responsible for any damage or data lost during the installation process. Do backup your microSD card if you have any concern.
Hardware:
The LoRa Basics™ Station protocol simplifies management of large scale LoRaWAN networks. LoRa Basics™ Station is the preferred way of connecting Gateways to The Things Stack. This section contains information for connecting your gateway to The Things Stack using LoRa Basics™ Station and its subprotocols.
Some of the advantages of LoRa Basics™ Station over the legacy UDP Packet Forwarder are:
LoRa Basics™ Station contains two sub protocols for connecting Gateways to Network Servers, LoRaWAN Network Server (LNS) and Configuration and Update Server (CUPS). For this tutorial, I’m using the LNS configuration.
LNS establishes a data connection between a LoRa Basics™ Station gateway and a Network Server (in this case, The Things Stack). LoRa® uplink and downlink frames are exchanged through this data connection. The LNS protocol is required for sending and receiving LoRaWAN data.
I tested this gateway on a Raspberry Pi 3 Model B+ with Debian Bullseye 11.0 (release date on 30th October 2021) but it should work on all types of OS version.
Attach LoRa Gateway HAT 915 to the Raspberry Pi board. Recommend to use Raspberry Pi 3B or 3B+ as it does not need the powerful processing power on the Raspberry Pi 4B, and of course, Raspberry Pi 4B will generate more heat as it is more powerful. Yet, the setup should be compatible with Raspberry Pi 4B.
ALWAYS remember to attach an antenna to the gateway before power ON the Raspberry Pi.
Connect Raspberry Pi to Ethernet or WiFi.
Download and install latest Raspberry Pi OS into the SD Card.
Insert the SD card into the Raspberry Pi board, attach mouse, keyboard and monitor before power ON the Raspberry Pi.
I used terminal remotely from my laptop. To do that, enable SSH interface in the Preferences > Raspberry Pi Configuration. Then, open terminal and search for the IP address of your Raspberry Pi. Use ifconfig
command.
Download PuTTY software. Insert the IP address and you can control the terminal remotely.
Open the terminal. Use raspi-config utility to enable SPI (in Interface Options) and also expand the filesystem (in Advanced Options):
sudo raspi-config
Reboot (it will ask on exit, but you can do it manually with sudo reboot
).
Make sure you have an updated installation and install git:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git
Get the source code. Since I have downloaded the source code, the file is already exists.
git clone https://github.com/lorabasics/basicstation.git
Compile the source code.
cd basicstation
make platform=rpi variant=std
You need to login root mode when conducting the next steps. This is because, modifying a few important files need permissions from the root.
Copy the station file to the /opt/basicstation/bin directory.
sudo su -
mkdir /opt/basicstation
mkdir /opt/basicstation/bin
You must use cd
command to stay in specific directory and make changes to the files in that directory. Once finished, just enter only the cd
to return at /root directory again.
cd /home/pi/basicstation
cp build-rpi-std/bin/station /opt/basicstation/bin
You can determine if the station file has successfully copied to the /opt/basicstation/bin directory by viewing through the desktop GUI. For other options, I’m using the WinSCP application to go through all the directories or files in the Raspberry Pi.
Create config directory:
mkdir /etc/basicstation
Go to /lib/systemd/system directory and create the service file:
cd /lib/systemd/system
nano basicstation.service
with this content here.
Then, press Ctrl+X to exit, press Y to save and Enter.
The next step is for the The Things Network setup. Go to the TTN v3 website.
Fill in Username, Email address, Password and click create account.
Go to TTN V3 console. Select a cluster based on YOUR region to start adding devices and gateways. In my case, I will choose Australia 1 since I am located in Asia region.
Register a new gateway and fill in the required information. The gateway ID must be unique and you can fill anything for gateway name and gateway description.
For Gateway EUI, you can get it from your Rasppberry Pi MAC address. Since the MAC address has 12 characters and the gateway EUI requires 16 characters, you can add FF FE characters in the middle of the MAC address.
For example, if the MAC address is A1 B2 C3 D4 E5 F6, the gateway EUI should be A1 B2 C3 FF FE D4 E5 F6.
Check the Require authenticated connection box.
Choose the frequency plan based on YOUR region and click create gateway.
A litlle bit explanation about the LoRaWAN frequency plan. This is a list of frequency plan definitions used in The Things Network. These frequency plans are based on what is specified in the LoRaWAN regional parameters document. In my case, since I’m living in Malaysia, the LoRaWAN frequency used must be within this list. It become an obligation to follow this one since it also has been stated in the regulatory for wireless communication.
To know which frequency plan to use in your country, see the list of frequency plans by country list. In my case, I will choose AS920-923.
To check if the The Things Stack correctly uses the LoRaWAN frequency within the range for your country, you can download the global_conf.json in your gateway overview. Find the lines that show the minimum and maximum frequency.
You had successfully create a gateway.
Done with the TTN website, go back to the terminal. Change current working directory to cd/etc/basicstation directory and create station.conf file:
cd /etc/basicstation
nano station.conf
Copy the content here and paste in the terminal.
Important: Get the Gateway EUI parameter from the TTN v3 console’s gateway info and put it on the routerid parameter.
The “FF FF FF FF FF FF FF FF” value is just a sample for gateway EUI since we cannot expose the gateway EUI (MAC address).
PLEASE refer to YOUR TTN v3 console’s gateway and replace the “ffffffffffffffff” value of routerid parameter with YOUR gateway EUI.
Then, press Ctrl+X to exit, press Y to save and Enter.
Go to /etc/basicstation directory and create the tc.trust file:
cd /etc/basicstation
nano tc.trust
create the file tc.trust with this content.
Copy all the contents and paste in the tc.trust. This is the public certificate of the SSL TTN servers.
Then, press Ctrl+X to exit, press Y to save and Enter.
Stay at the same directory and create the tc.uri file:
cd /etc/basicstation
nano tc.uri
Create the file tc.uri with this content:
wss://au1.cloud.thethings.network:8887
This is the TTN v3 secure websocket server.
THIS SERVER IS FOR THE ASIAN USERS. IF YOU ARE NOT AN ASIAN USER USE THE SERVER IN Gateway Server address ON YOUR TTN v3 INFO PAGE.
Then, go to the TTN v3 console on your new gateway API keys section and add a new key.
Call it LNS and check the :
Grant individual rights box
Link as Gateway to a Gateway Server for traffic exchange, i.e. write uplink and read downlink box
Save changes.
Important! Write down the API key in a text file and save it for next usage, YOU CANNOT SEE THE KEY AFTERWARDS!!! If you lose it you must delete and recreate it!!!
Stay in the same directory and create the tc.key file using YOUR API key by replacing the your-lns-api-key in the command below. Please recheck and open the tc.key file to see if your API key is there.
cd /etc/basicstation
export LNS_KEY="your-lns-api-key"
echo "Authorization: Bearer $LNS_KEY" | perl -p -e 's/\r\n|\n|\r/\r\n/g' > tc.key
Go to /boot directory and open the config.txt file.
cd /boot
nano config.txt
Add this line in the [all] section of config.txt file.
dtoverlay=spi0-1cs
Then, go to /etc/basicstation directory and create a reset_gw.sh file.
cd /etc/basicstation
nano reset_gw.sh
Use this script for the reset_gw.sh file to reset the RHF0M301.
Then, press Ctrl+X to exit, press Y to save and Enter.
Stop the ttn-gateway.service.
systemctl stop ttn-gateway.service
Disable the ttn-gateway.service.
systemctl disable ttn-gateway.service
Check the ttn-gateway.service status.
systemctl status ttn-gateway.service
The command should show this if you have installed the Semtech UDP packet forwarder before this:
ttn-gateway.service - The Things Network Gateway
Loaded: loaded (/lib/systemd/system/ttn-gateway.service; disabled)
Active: inactive (dead)
In this way we disable the old packet forwarder but don’t uninstall it, if you have some problem with the Basic Station you could quickly reenable the old.
Enable the basicstation.service.
systemctl enable basicstation.service
Start the basicstation.service.
systemctl start basicstation.service
Check the basicstation.service status.
systemctl status basicstation.service
The command should show something like this:
basicstation.service - Basic Sation TTN V3 service
Loaded: loaded (/lib/systemd/system/basicstation.service; enabled)
Active: active (running) since gio 2021-07-22 05:17:08 CEST; 2 weeks 4 days ago
Main PID: 332 (station)
CGroup: /system.slice/basicstation.service
└─332 /opt/basicstation/bin/station -h /etc/basicstation
Open the gateway platform in The Things Stack and you should see an update in the live data. The gateway should be ready to receive any data from the node if the live data displays two line like these:
To send data to The Things Stack through this gateway, you will need at least one node functioning in your area.
Kindly refer to the next tutorial for End Node device setup and how to display data on The Things Stack V3.
I have encountered a few errors/problems during this gateway setup. For example, if you having a result like this:
Consider checking the basicstation log files on the Raspberry Pi. They should be in /var/log. The log file will let you see what is happening. If you want more detail in the log file, you can change the log_level to verbose in the station.conf file.
cd /var/log
nano basicstation.log
It is possible that the SX130X chip needs a reset before Basics Station starts. Check that you have chosen the correct reset pin. If your adapter board connects the SX130X reset pin to pin 25 on the Raspberry Pi, then the option in reset_gw.sh will be needed to make pin 25 available.
Lastly, if your gateway suddenly cannot operate after you restart your gateway, please check again the station.conf file. Sometimes it become unknown values and you just need to replace all the unknown values with the right contents that you had setup before this.
References:
https://github.com/bigjohnson/iC880A-SPI-basics-station
https://www.thethingsnetwork.org/forum/t/rhf0m301-raspberry-pi-with-basics-station/52595
https://www.thethingsindustries.com/docs/gateways/lora-basics-station/lns/
https://www.thethingsindustries.com/docs/reference/root-certificates/