Make Single Channel LoRaWAN gateway with Raspberry Pi

Somsak Lima
6 min readJan 13, 2024

--

Must-have equipment

1. Raspberry Pi 3 Model B or PI4 or PI 0W 1 board with a 5V power adapter size not less than 2 A
2. HDMI Monitor, Mouse, Keyboard, used only during installation
3. LoRaWan Shield for Raspberry Pi, (Ordered from Click)
4. Micro SD card Size not less than 16 G
5. RJ45 LAN cable

Write SDcard with Raspberry Pi Imager Program

When installing, select Raspberry Pi OS(other).

Then select Raspberry Pi OS(Legacy, 64-bit) Full Debian Bulleye.

How to install Hardware

  • Put the LoRaWan Shield into the Raspberry Pi Socket as shown in the picture.
  • Insert the Micro SDcard into the Raspberry Pi slot.
  • Plug the HDMI cable into the monitor.
  • Plug the keyboard and mouse cable into the RPI USB port.
  • Connect RPI to the Internet via Lan cable.
  • Plug in the power to the RPI. You will see a green light and a red light flashing. After booting is complete, you will see the screen as shown.

Note:
If you do not have or do not use a LoRaWan Shield, use the RFM95W instead, connect the cable from the RFM95W to the Raspberry Pi as follows.

RFM WirePi 
NAME NAME Physical
3.3V — 3.3V (header pin #1)
GND — GND (pin #6)
MISO — MISO (pin #21)
MOSI — MOSI (pin #19)
SCK — SCLK (pin #23)
NSS — GPIO6 (pin #22)
DIO0 — GPIO7 (pin #7)
RST — GPIO0 (pin #11)

How to install software

  • Please install PI first.
  • Enable SPI

Call Raspberry Pi Configuration

Go to the Preference/ Raspberry Pi Configuration menu, select the Interfaces tab, click Enabled on SSH and SPI and press OK.

Update PI and then Reboot.

sudo apt update 
sudo apt upgrade
sudo apt autoremove
sudo reboot

How to Install Wiring Pi

Check by following command whether wiring Pi was already installed or not.

gpio readall 

If it is not installed , you may install it using the method below.

sudo apt install wiringpi

Start installing the Single Channel Packet Forward program.

Reboot the Pi once. When the PI turns on again, download the Single Channel Packet Forward program and make the program.

cd /home/pi 
git clone https://github.com/m2mlorawan/single_chan_pkt_fwd
cd ~/single_chan_pkt_fwd
sudo cp global_conf.json global_conf.json.org
make

Remark****
After using Make, you will see the message as follows. If there is a Warning, don’t pay attention.

g++ -std=c++11 -c -Wall -I include/ base64.cg++ -std=c++11 -c -Wall -I include/ single_chan_pkt_fwd.cppg++ single_chan_pkt_fwd.o base64.o -lwiringPi -o single_chan_pkt_fwd

Note:
If using RPI0, change eth0 in the single_chan_pkt_fwd.cpp file to wlan0 on line 691 from
strncpy(ifr.ifr_name, “eth0”, IFNAMSIZ-1); // can we rely on eth0?
is
strncpy(ifr.ifr_name, “wlan0”, IFNAMSIZ-1); // can we rely on eth0?

Go into Directory single_chan_pkt_fwd

cd ~/single_chan_pkt_fwd

Before using, set the config file by changing the values ​​in the file. global_conf.json with the command

sudo nano global_conf.json

example

{
"SX127x_conf":
{
"freq": 923200000,
"spread_factor": 7,
"pin_nss": 6,
"pin_dio0": 7,
"pin_rst": 0,
"pin_led1":4
},
"gateway_conf":
{
"ref_latitude": 0.0,
"ref_longitude": 0.0,
"ref_altitude": 10,

"name": "SC Gateway",
"email": "contact@whatever.com",
"desc": "M2M Single Channel Gateway on RPI",

"servers":
[
{
"address": "192.168.1.100",
"port": 1700,
"enabled": false
},
{
"address": "eu1.cloud.thethings.network",
"port": 1700,
"enabled": true
}
]
}
}

Change Freq, SF, Server Address as you want.

Try running the program to let the program check the Gateway ID value, which is the value that must be registered on the TTN website.

sudo /home/pi/single_chan_pkt_fwd/single_chan_pkt_fwd

In the case of using a new version of Raspbian, running with sudo and encountering the error Unrecognized transceiver: Success

You may change it to not use sudo as follows.

/home/pi/single_chan_pkt_fwd/single_chan_pkt_fwd

will see the message

server: .address = eu1.cloud.thethings.network; .port = 1700; .enable = 1 
server: .address = test.mosquitto.org; .port = 1883; .enable = 0
Gateway Configuration
Lora (yourname@gmail.com)
Single Channel Gateway
Latitude=8.07999992
Longitude=98.80999756
Altitude=10
Trying to detect module with NSS=6 DIO0=7 Reset=0 Led1=4
SX1276 detected, starting.
Gateway ID: b8:ab:ff:ff:ff:ff:ff:ff
Listening at SF7 on 923.200000 Mhz.
— — — — — — — — — — — — — — — — — — -
stat update: 2017–11–13 23:02:20 GMT no packet received yet

Exit the program, press Ctrl C, stop, write down the Gateway ID value: use it to register with the TTN website, for example b8:ab:ff:ff:ff:ff:ff:ff

If you see meassge “Unable to open SPI device: No such file or directory”, you have to enable SPI first.

If you test Run and it works normally. Install the program so that it runs every time you turn on the Pi.

sudo make install

will see the message

sudo cp -f ./single_chan_pkt_fwd.service /lib/systemd/system/ 
sudo systemctl enable single_chan_pkt_fwd.service
Created symlink /etc/systemd/system/multi-user.target.wants/single_chan_pkt_fwd.service ? /lib/systemd/system/single_chan_pkt_fwd.service.
sudo systemctl daemon-reload
sudo systemctl start single_chan_pkt_fwd
sudo systemctl status single_chan_pkt_fwd -l
? single_chan_pkt_fwd.service — Lora Packet Forwarder
Loaded: loaded (/lib/systemd/system/single_chan_pkt_fwd.service; enabled; ven
Active: active (running) since Mon 2017–11–13 22:56:57 UTC; 259ms ago
Main PID: 1136 (single_chan_pkt)
CGroup: /system.slice/single_chan_pkt_fwd.service
mq1136 /home/pi/single_chan_pkt_fwd/single_chan_pkt_fwdNov 13 22:56:57 raspberrypi systemd[1]: Started Lora Packet Forwarder.

Reboot the machine again.

sudo reboot

Check that the program single_chan_pkt_fwd Is it running with the ps ax command? You will see a line similar to the following.

728 ? Ss 0:02 /home/pi/single_chan_pkt_fwd/single_chan_pkt_fwd

Tip! View Gateway Log in real time

journalctl -f -u single_chan_pkt_fwd

Tip! Start or Stop Service command

systemctl start single_chan_pkt_fwd 
systemctl stop single_chan_pkt_fwd
systemctl status single_chan_pkt_fwd

When running with Manual, if the gateway starts and can receive data, the values ​​will be displayed on the screen as in the example.

Packet RSSI: -62, RSSI: -118, SNR: 9, Length: 17 Message:' @j ..&….l……`' 
rxpk update: {“rxpk”:[{“tmst”:1933922638,” freq”:923.2,”chan”:0,”rfch”:0,”stat”:1,”modu”:”LORA”,”datr”:”SF7BW125”,”codr”:”4/5”,” rssi”:-62,”lsnr”:9.0,”size”:17,”data”:”QGoVASaAAAABbP4UEwjy7WA=”}]}
stat update: 2017–11–13 23:15:52 GMT 1 packet received
Packet RSSI: - 72, RSSI: -116, SNR: 8, Length: 17 Message:' @j ..&……….UY'
rxpk update: {“rxpk”:[{“tmst”:1964565663,”freq”:923.2, ”chan”:0,”rfch”:0,”stat”:1,”modu”:”LORA”,”datr”:”SF7BW125”,”codr”:”4/5”,”rssi”:-72 ,”lsnr”:8.0,”size”:17,”data”:”QGoVASaAAwABuh2D3bjVVVk=”}]}

Single Channel Gateway can only use with ABP authentication method. Select ABP, when register a new device

Remark

1.Enable SPI in Text Mode

Open Console and execute

sudo raspi-config

Select 3 Interface Option

Select I4 SPI

Select Yes and OK to finish setting.

2. If after running single_chan_pkt_fwd, gateway ID: 00:00:00:ff:ff:00:00:00.

 pi@raspberrypi:~/single_chan_pkt_fwd $ ./single_chan_pkt_fwd
server: .address = 192.168.1.100; .port = 1700; .enable = 0
server: .address = eu1.cloud.thethings.network; .port = 1700; .enable = 1
Gateway Configuration
SC Gateway (contact@whatever.com)
M2M Single Channel Gateway on RPI
Latitude=0.00000000
Longitude=0.00000000
Altitude=10
Trying to detect module with NSS=6 DIO0=7 Reset=0 Led1=4
SX1276 detected, starting.
Gateway ID: 00:00:00:ff:ff:00:00:00

File single_chan_pkt_fwd.cpp is needed to be edited at line 691.

Change from
strncpy(ifr.ifr_name, “eth0”, IFNAMSIZ-1); // can we rely on eth0?
to
strncpy(ifr.ifr_name, “wlan0”, IFNAMSIZ-1); // can we rely on eth0?

หรือ Clone ด้วยคำสั่ง

git clone https://github.com/m2mlorawan/single_chan_pkt_fwd_PiZero

3. Problem Sometime the gateway works but sometime it does not work.

The problem may arise from 2 problems.

First Problem
Select your gateway and click General settings. Expand LoRaWAN option and click to unselect Enforce duty cycle.

Second problem

Select reset frame counter in your device settings. Expand Network Layer. Click Advance Mac Settings. Enable by selecting Resets frame counters.

--

--

Somsak Lima
Somsak Lima

Written by Somsak Lima

สนับสนุนและส่งเสริมให้ผู้สนใจสามารถใช้งานเทคโนโลยี LoRa และ LoRaWAN ได้ โดยนำความรู้ที่ได้ไปต่อยอดเพื่อใช้งาน