Bukit Mertajam, Penang

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, yet they do not require high power or data streaming. This is the gap that LoRaWAN bridges with its low power, low payload feature. In LoRaWAN systems, the LoRa Gateway plays an important role because its job is to receive signals from LoRa end devices/nodes and upload them to the network (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 as an obstacle to the wide implementation of this new LoRaWAN technology in Malaysia, Cytron Technologies Sdn Bhd proudly introduces HAT-LRGW-915 (Cytron 915MHz 8 Channel LoRa Gateway HAT).

This HAT basically is a plug and play LoRa gateway module. By simply mounting this HAT on a Raspberry Pi board, the Raspberry Pi can instantly become a LoRa Gateway! With proper software setup, Raspberry Pi can work as well as any other standard LoRa Gateway!

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 as you will need it to test the Gateway’s functionality. If you don’t already have a LoRa node, you can refer to this tutorial to quickly build a 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

The 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 transform their existing Raspberry Pi into a LoRa Gateway without reformatting the SD card, please skip to this section.

PART 1 – Build hardware from zero

1. Download this image onto your PC. This image is a modified Raspbian Jessie Lite image with the LoRa Gateway software pre-installed. The download might take time so wait patiently.

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

Etcher GUI Interface
Etcher GUI Interface

3. Plug the HAT-LRGW-915 onto your Raspberry Pi and install the antenna.

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

5. As LoRa Gateways requires Internet to transfer data packets to cloud server, we will need to connec the Raspberry Pi to the Internet. Connect the Raspberry Pi to your WiFi/Internet router or modem through an Ethernet cable.

6. Power up your Raspberry Pi with a 5V 2.5A power adapter. If it successfully connects to the Internet, the LoRa Gateway program should boot up automatically.

How do we know if LoRa Gateway is up and running?
We can access Raspberry Pi from our PC and check it out, but in a truely old fashioned way – via command terminal. Since we are using Raspbian Jessie Lite on Raspberry Pi, no Desktop GUI will be able to access the Raspberry Pi. Everything must be written through command lines – But no worries, our instructions will 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 here. Choose a driver based on your PC OS system type.

2. Run the installer and 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. You can also search up its installer for other OS such as Mac OSX or Linux.

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. Select “Serial” connection type (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 the same configuration to be used next time, I would suggest saving the session. Type a random name in text box under ‘Saved Sessions’ label and click ‘Save’. Next time you open Putty software, you just have to select the saved session, click ‘Load’ and 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 onto the screen- that’s Raspberry Pi responding to what you have entered. If not, you have to go back to the previous section and check your settings.

root

Password:

2. From the text, it says it requires login password. By default it is ‘cytron’. (FYI if you are new to command terminal, the password remains invisible as type.) You can press backspace or delete as many times as you like, just make sure you type the correct one before press Enter.

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.
root@cytron-lora-gw:~#

4. Check if the Raspberry Pi has established Ethernet connection by typing ifconfig in PUTTY terminal. If the Ethernet (not Internet, yet) connection is successful, you should able to see IP address shown in eth0.

root@cytron-lora-gw:~# 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)

root@cytron-lora-gw:~# 

5. Check if the Internet connection is established by typing ping google.com. If the Internet connection successful, the following lines should appear, indicating successful pinging to google.com (which means it can access the Internet).

root@cytron-lora-gw:~# 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
root@cytron-lora-gw:~#

6. Type sudo journalctl -u ttn-gateway -f -n 50 to check the logs of LoRa Gateway Program. The following what it should look like (your results might be differ slightly, don’t worry about it). Then, press Ctrl+C to terminate the process.

 
root@cytron-lora-gw:~# 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. Then, press Ctrl+C to terminate the process.

root@cytron-lora-gw:~# 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..(H_@.@......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
E@. ..@.3...4>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..(JR@.@......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
E@. .W@.3...4>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..(Jq@.@......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
E@. ..@.3...4>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..(K.@.@..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
E...K.@.@..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. Start the command tcpdump -AUq port 1700 to monitor the packets sent from LoRa devices/nodes.

3. Your screen should show similar lines to the following. They indicate that there is constant UDP connection between LoRa Gateway and the TTN network server and the program is running correctly. If nothing shows up, there may not be Internet connection.

10:44:29.726483 IP ec2-52-62-83-250.ap-southeast-2.compute.amazonaws.com.1700 > cytron-lora-gw.59053: UDP, length 4
E@. ?5@.3...4>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..(..@.@./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
E@. 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..(.L@.@..$...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
E@. F.@.3..h4>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..(..@.@.-....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
E@. Jp@.3...4>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
E....j@.@.+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":"support@cytron.com.my","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
E@. L.@.3..k4>S....t......_2..g...............

4. If the packets from LoRa node reach the Gateway successfully, following data will appear. The data shows 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 displaying on your screen.

{"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. Even though packets are successfully sent to the TTN network server, it doesn’t mean the server will process the packets. You need to register a TTN account on their website and register the LoRa node under your account. If you followed our LoRa Node build tutorial, your LoRa node would have already been registered to TTN.

7. Once your LoRa node is registered to TTN, you can check your TTN dashboard to see if  your data is being displayed on the 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 Posts

Comments (1)

Hi, i need help!.. After following steps of tutorial and setup the LoRa Gateway, I can´t connect to internet.
I made:
1) Installed modified´s Raspbian Jessie Lite image with the LoRa Gateway software pre-installed and I followed steps but when try to check if the Internet connection is established by doing ping, it failed.
2) I tried whit the advanced installation from existing Raspbian OS image and its doesnt work too. I cant connect to internet.
What can be the problem?

P.D. I bought the Cytron 915MHz LoRa Gateway Raspberry Pi Hat (HAT-LRGW-915)

Leave a comment