Lesson 2: Setting up a Raspberry Pi 3 LoRa Gateway with HAT-LRGW-915

Last Updated on 15 Sep 2017


INTRODUCTION

Lately LoRaWAN has been increasingly famous in the area of Internet of Things (IoT) applications. Many applications in our daily lives require remote control or monitoring, but at the same time high power consumption or data streaming is not necessary. This is where LoRaWAN came in and take its role due to its feature – low power, low payload. In LoRaWAN, LoRa Gateway plays an important role because its job is to receive signals from LoRa end devices/nodes and upload them to cloud server via Internet.

However, most of the industrial-grade LoRa Gateways are pricy. Base price mostly starts from $USD 250-300 and above, some can cost even up to $USD 2000! Seeing the price might become an obstacle to widely introduce this new technology LoRa and LoRaWAN in Malaysia, Cytron Technologies Sdn Bhd proudly introduces HAT-LRGW-915 (Cytron 915MHz 8 Channel LoRa Gateway HAT).

This HAT basically is a plugin LoRa gateway module, with simple mount of this HAT on famous Raspberry Pi board, this whole thing can instantly become a LoRa Gateway ready to be used! With proper software setup, Raspberry Pi can work same like any other standard LoRa Gateway, and you are ready to explore in this new technology!

Cytron 915MHz LoRa Gateway Raspberry Pi Hat (HAT-LRGW-915)
Cytron 915MHz LoRa Gateway Raspberry Pi Hat (HAT-LRGW-915)

PREREQUISITE

Before getting started, make sure you have at least one LoRa node to proceed with this tutorial if you want to test the functionality of LoRa Gateway. If you currently don’t have any, you can refer to this tutorial to quick build 1 set of LoRa node.

OBJECTIVE

By following this tutorial you will learn:

  1. Setup a LoRa Gateway with Raspberry Pi 3 and HAT-LRGW-915
  2. Monitor LoRa signals/packets from LoRa end devices at Raspberry Pi 3

HARDWARE REQUIREMENT

  1. Raspberry Pi 3 Model B (1GB)
  2. Blank 8/16GB SD Card
  3. Cytron 915MHz 8 Channel LoRa Gateway HAT (HAT-LRGW-915)
  4. 5V 2.5A power adapter
  5. Ethernet cable

SOFTWARE REQUIREMENT

  1. Etcher
  2. Putty

STEPS

Following steps will guide you to setup a LoRa Gateway starting from a blank SD card (no pre-installed OS on SD card). For those who are interested to make their existing Raspberry Pi into LoRa Gateway without reformat SD card, please skip to this section.

PART 1 – Build hardware from zero

1. First of all, download this image on your PC. This image is modified Raspbian Jessie Lite image with LoRa Gateway software installed. The download might take time so wait patiently.

2. Insert blank SD card to your PC and burn the downloaded image into SD card using software Etcher. Step by step instructions for burning process will be shown when you open the software.

Etcher GUI Interface
Etcher GUI Interface

3. Plug in HAT-LRGW-915 on your Raspberry Pi with antenna installed on the HAT.

4. Insert SD card with image ready into Raspberry Pi SD card slot.

5. LoRa Gateway requires Internet to transfer data packets to cloud server, in this case we are using TTN network server. Therefore we will need Raspberry Pi to connect to Internet. Plug in one end of Ethernet cable to Raspberry Pi and another end to your WiFi/Internet router or modem.

6. Power up your Raspberry Pi with 5V 2.5A power adapter. After a while, the LoRa Gateway programme should be up and running automatically if it connects to Internet successfully.

How do we know if LoRa Gateway is up and running? Yup we can access Raspberry Pi from our PC and check it out, but in old fashioned way, a.k.a via command terminal. We are using Raspbian Jessie Lite on Raspberry Pi, remember? Meaning no Desktop GUI available to access Raspberry Pi, everything must be written in command line. No worries, follow the following instructions to get you through.

PART 2 – Setup before access to LoRa Gateway

1. Install CH340G UART drivers on your PC. The driver installer can be downloaded from here. Choose based on your PC OS system type.

2. Run the installer. Wait until the installation finishes. The installation may inform you that driver has been installed already, if so just skip the installation.

3. Install Putty software. You can download Windows installer here. Of course if you are using other OS like Mac OSX or Linux, you can search for installer pretty easy too via Google. Install it after download.

4. Connect Debug USB Port on your Raspberry Pi Hat to your PC via micro USB cable. Make sure at that time Raspberry Pi is already powered up.

5. If CH340G UART driver is properly installed, you should be able to check which port Raspberry Pi connected to your PC. For Windows, it is normally named as COMx where x is a number. For Linux and OSX, it starts with /dev/*.

6. Open Putty software. Select connection type to Serial (by default it is set to SSH). Set Serial Line to your dedicated port(COMx, /dev/*, etc), set baudrate to 115200. Then click Open at the bottom of dialog box to begin the session.

PUTTY Interface
PUTTY Interface

If you want same configuration to be used next time, I would suggest save the session. Type a random name in text box under ‘Saved Sessions’ label and click ‘Save’. Next time you open Putty software, you select the saved session, click ‘Load’ then open.

PART 3 – Testing access to LoRa Gateway via PUTTY terminal

1. Once the session is successfully opened, a black screen will appear. This is PUTTY terminal. In PUTTY terminal, try to type ‘root’ and press Enter. You should be able to see some texts popping out from the screen. If you see those, it means Raspberry Pi is giving response on what you have entered. Else you have to check your settings at previous section.

root
Password:

2. From the text, it says it requires login password. By default it is ‘cytron’. If you are new to command terminal, FYI the password remains invisible as you are typing. So just make sure you type the correct one then press Enter. If you are not sure, just press backspace or delete many times before you start entering password again.

3. You will see this if login is successful.

 
Last login: Tue Aug 22 17:15:55 MYT 2017 on ttyS0
Linux cytron-lora-gw 4.4.50-v7+ #970 SMP Mon Feb 20 19:18:29 GMT 2017 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
[email protected]:~#

4. Type ifconfig in PUTTY terminal. This command checks Raspberry Pi Ethernet connection. By now you should able to see IP address shown in eth0.

[email protected]:~# ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:e5:50:23  
inet addr:192.168.1.116  Bcast:192.168.1.255  Mask:255.255.255.0
inet6 addr: fe80::bea9:4a56:effc:e4e4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:235 errors:0 dropped:0 overruns:0 frame:0
TX packets:100 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:21416 (20.9 KiB)  TX bytes:13049 (12.7 KiB)
lo        Link encap:Local Loopback  
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:65536  Metric:1
RX packets:608 errors:0 dropped:0 overruns:0 frame:0
TX packets:608 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1 
RX bytes:48032 (46.9 KiB)  TX bytes:48032 (46.9 KiB)
wlan0     Link encap:Ethernet  HWaddr b8:27:eb:b0:05:76  
inet6 addr: fe80::d500:6d3b:3438:32c/64 Scope:Link
UP BROADCAST MULTICAST  MTU:1500  Metric:1
RX packets:68 errors:0 dropped:6 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:19203 (18.7 KiB)  TX bytes:0 (0.0 B)
[email protected]:~# 

5. Check Internet connection by typing ping google.com. If connection successfull, following lines should appear, they are indicating pinging to google.com is successful, which means Internet can be accessed.

[email protected]:~# ping google.com
PING google.com (172.217.31.110) 56(84) bytes of data.
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=1 ttl=57 time=8.60 ms
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=2 ttl=57 time=7.20 ms
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=3 ttl=57 time=8.17 ms
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=4 ttl=57 time=7.43 ms
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=5 ttl=57 time=8.06 ms
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=6 ttl=57 time=8.04 ms
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=7 ttl=57 time=7.80 ms
...

Press Ctrl+C to stop the process.

...
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=6 ttl=57 time=8.04 ms
64 bytes from kul08s08-in-f14.1e100.net (172.217.31.110): icmp_seq=7 ttl=57 time=7.80 ms
^C
[email protected]:~#

6. Type sudo journalctl -u ttn-gateway -f -n 50 to check the logs of LoRa Gateway Programme. Following is the example log from LoRa Gateway programme. Your result might be differ but for now you don’t need to worry about it. Press Ctrl+C to terminate the process.

 
[email protected]:~# sudo journalctl -u ttn-gateway -f -n 50
-- Logs begin at Tue 2017-08-22 17:20:39 MYT. --
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: INFO: [down] for server router.au.thethings.network PULL_ACK received in 225 ms
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: INFO: [down] for server router.au.thethings.network PULL_ACK received in 225 ms
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: INFO: [down] for server router.au.thethings.network PULL_ACK received in 225 ms
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: INFO: [down] for server router.au.thethings.network PULL_ACK received in 225 ms
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: INFO: [down] for server router.au.thethings.network PULL_ACK received in 225 ms
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: INFO: [down] for server router.au.thethings.network PULL_ACK received in 225 ms
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: ##### 2017-09-14 02:29:41 GMT #####
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: ### [UPSTREAM] ###
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # RF packets received by concentrator: 1
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # CRC_OK: 100.00%, CRC_FAIL: 0.00%, NO_CRC: 0.00%
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # RF packets forwarded: 1 (32 bytes)
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # PUSH_DATA datagrams sent: 2 (454 bytes)
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # PUSH_DATA acknowledged: 0.00%
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: ### [DOWNSTREAM] ###
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # PULL_DATA sent: 6 (100.00% acknowledged)
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # PULL_RESP(onse) datagrams received: 0 (0 bytes)
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # RF packets sent to concentrator: 0 (0 bytes)
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # TX errors: 0
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: ### [GPS] ###
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: # GPS sync is disabled
Sep 14 10:30:11 cytron-lora-gw ttn-gateway[397]: ##### END #####
...

7. Type tcpdump -AUq port 1700. This command is to monitor traffic of LoRa packets from LoRa devices or called LoRa Node. Press Ctrl+C to terminate the process.

[email protected]:~# tcpdump -AUq port 1700
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:34:50.418723 IP cytron-lora-gw.57330 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 12
E..([email protected]@......t4>S.......Jz.(...'....P#
10:34:50.644735 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.57330: UDP, length 4
[email protected] [email protected]>S....t.........(................
10:34:55.438678 IP cytron-lora-gw.57330 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 12
E..([email protected]@......t4>S.......Jz.L...'....P#
10:34:55.664721 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.57330: UDP, length 4
[email protected] [email protected]>S....t.........L................
10:35:00.458681 IP cytron-lora-gw.57330 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 12
E..([email protected]@......t4>S.......Jz.j...'....P#
10:35:00.684810 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.57330: UDP, length 4
[email protected] [email protected]>S....t.......|.j................
10:35:05.478703 IP cytron-lora-gw.57330 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 12
E..([email protected]@..h...t4>S.......Jz.....'....P#
10:35:05.675157 IP cytron-lora-gw.51661 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 255
[email protected]@..g...t4>S.......Km.....'....P#{"rxpk":[{"tmst":956404596,"time":"2017-09-14T02:35:05.675068Z","chan":0,"rfch":0,"freq":920.000000,"stat":1,"modu":"LORA","datr":"SF9BW125","codr":"4/5","lsnr":12.2,"rssi":-99,"size":32,"data":"QBocAyYAwGABHl7G6X39CgfH10gvpFMad6L9j3ylm5o="}]}

PART 4 – Monitor LoRa signals/packets sent from LoRa Node at LoRa Gateway

1. Right now you should have at least 1 LoRa Node ready. Make sure your LoRa Node is powered up.

2. The command tcpdump -AUq port 1700 will be used to monitor the packets sent from LoRa devices/nodes. Start the command.

3. See if you have lines similar to the following appearing on your screen. In short, these lines shows constant UDP connection between LoRa Gateway and TTN network server, meaning LoRa Gateway programme is up and running. If the programme is not running or Internet failed, nothing will show up after the command tcpdump -AUq port 1700 starts.

10:44:29.726483 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.59053: UDP, length 4
[email protected] [email protected]>S....t......?R..................
10:44:33.618709 IP cytron-lora-gw.49106 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 12
E..([email protected]@./n...t4>S.......Jz.p...'....P#
10:44:33.848591 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.49106: UDP, length 4
[email protected] C(@.3...4>S....t.........p................
10:44:38.648689 IP cytron-lora-gw.49106 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 12
E..([email protected]@..$...t4>S.......Jz.>...'....P#
10:44:38.878779 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.49106: UDP, length 4
[email protected] [email protected]>S....t......L..>................
10:44:43.678693 IP cytron-lora-gw.49106 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 12
E..([email protected]@.-....t4>S.......Jz.A...'....P#
10:44:43.908543 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.49106: UDP, length 4
[email protected] [email protected]>S....t.........A................
10:44:48.006465 IP cytron-lora-gw.59053 > ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700: UDP, length 198
[email protected]@.+L...t4>S.......K4..g..'....P#{"stat":{"time":"2017-09-14 02:44:47 GMT","rxnb":2,"rxok":1,"rxfw":1,"ackr":0.0,"dwnb":0,"txnb":0,"pfrm":"IMST + Rpi","mail":"[email protected]","desc":"Cytron Indoor LoRa Gateway"}}
10:44:48.244704 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.59053: UDP, length 4
[email protected] [email protected]>S....t......_2..g...............

4. If the packets from LoRa node reach the Gateway successfully, following lines will appear. The data show the information of LoRa Packets from your LoRa node including the frequency, RSSI, encrypted data etc. If connection with TTN network server is already successful, those packets will be sent to TTN network server after this.

{"rxpk":[{"tmst":956404596,"time":"2017-09-14T02:35:05.675068Z","chan":0,"rfch":0,"freq":920.000000,"stat":1,"modu":"LORA","datr":"SF9BW125","codr":"4/5","lsnr":12.2,"rssi":-99,"size":32,"data":"QBocAyYAwGABHl7G6X39CgfH10gvpFMad6L9j3ylm5o="}]}

5. The packets sent to TTN network server doesn’t mean the server will process the packets you send. You will need to register an account in TTN and register the LoRa node under your account. If you followed our LoRa node build tutorial, your LoRa node has been registered to TTN.

7. If your LoRa node is registered to TTN, you can check your TTN dashboard and see if there is any data appearing on your dashboard. How to check it?

  1. Go to TTN applications page.Select the application in which your LoRa node is registered to.
  2. Select device (your LoRa node) from devices page under Applications > Your Application ID > Devices
  3. Under your Device page, select Data from menu located at top-right corner.
  4. Now you can check if your data is appearing on your dashboard. If it does, the gateway and LoRa node are working!

Congratulations! You have built yourself a LoRa Gateway. Now you can make couple of LoRa nodes and transmit data to TTN network server via your LoRa Gateway.

MISC – Advanced installation/ installation from existing Raspbian OS image

For advanced users, they can install LoRa Gateway software manually with existing Raspbian OS image.

1. Connect Raspberry Pi to Internet (Ethernet or WiFi).

2. Use raspi-config utility to enable SPI and also expand the filesystem.

sudo raspi-config

3. Configure time zone. It is convenient for checking the time when viewing logs.

sudo dpkg-reconfigure tzdata

4. Make sure you have an updated installation and install git

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git

5. Clone the installer and start the installation

git clone https://github.com/CytronTechnologies/RisingHF-gateway.git ~/RisingHF-gateway
cd ~/RisingHF-gateway
sudo ./install.sh

6. During the installation, enter your information such hostname, email etc.

7. After installation completes, the system will automatically reboot and LoRa Gateway is ready.

For more info, please refer to The Things Network Installer for RisingHF-based gateway.

What if I want to use WiFi instead of Ethernet?

Sure no problem at all! Again you can use PUTTY terminal to configure WiFi on Raspberry Pi.

1. Configure the wifi credentials (check here for additional details) by typing following command

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

2. And add the following block at the end of the file, replacing SSID and password to match your network, then save the file:

network={
ssid="The_SSID_of_your_wifi"
psk="Your_wifi_password"
}

For more info, check here

REFERENCES

  1. Official Documentation from The Things Network
  2. CytronTechnologies/RisingHF-gateway

Related Post

Installing Raspbian OS on Raspberry Pi for Windows

Raspberry Pi: Line Following Robot

Raspberry Pi: Control DC Motor using MDDS10

Raspberry Pi: GUI with a Remote Desktop Connection

Leave a Reply

Your email address will not be published. Required fields are marked *