wireless

Building a LoRaWAN gateway

We have designed our own LoRaWAN Gateway add-on Hat for the Raspberry Pi that enables a full 8 channel gateway to be created quickly and connect to The Things Network. The gateway is based on the RAKWireless RAK833 LoRa concentrator module. This is a mPCIe card and requires an adaptor to use. It is available in UART and UART/SPI configurations. The UART is not used in this application so only the SPI version is required. The code has been configured to work with this module.

LoRaWAN Gateway Kit

The Thing Innovations LoRaWAN gateway kit includes:

  • RAKWireless RAK833 mPCIe LoRa concentrator card.
  • Thing Innovations LoRa gateway Hat with GPS.
  • LoRa Antenna and u.Fl/SMA-RP pigtail
  • Small GPS Antenna and u.Fl/SMA pigtail.
Gateway kit
Gateway kit

Start by downloading the Raspbian Stretch Lite image and create a uSD for use in the Pi. The best solution to creating the uSD card that we’ve found is Balena Etcher. This is available from a number of platforms and is straightforward to use.

Once the uSD card has been written, you need to create a file called ssh in the root directory. This will enable the ssh server and allow us to access the pi remotely. One way to do this is to copy one of the other files such as cmdline.txt and rename it.

The code repository is available at https://github.com/thiseldo/RAK833-LoRaGateway-RPi and has the basic setup instructions.

Assemble gateway kit

The hat should be carefully pushed on to the GPIO connector on the Pi. If the RAK833 module is not already fitted then it should be first pushed into the socket (heatsink upwards) at about a 30′ angle, then pushed downwards to lock it into place.

The antenna connectors should be identified and pushed on to the correct terminal. The LoRa antenna pigtail has a pin in the centre of the SMA connector and connects to the u.Fl connector on the RAK833. The GPS antenna pigtail has a hole in the centre and connects to the u.Fl connector on the hat.

SMA - GPS
GPS SMA Connector
Con LoRa
LoRa Antenna SMA Connector

Completed gateway

Prepare Raspberry Pi

You should be able to login to the raspberry pi using a suitable SSH client. The hostname raspberrypi.local can be used in the ssh client providing there are no other devices with the same name already present on the network. The Pi needs to be prepared in order for the software to be installed. This involves using the raspi-config command to change a number of default settings.

$ sudo raspi-config

The following changes should be made:

  • Boot options -> Desktop/CLI -> Console
  • Interfacing options -> Enable SSH, Enable SPI, Login shell over serial disabled, serial interface enabled
  • Advanced -> Expand filesystem, Memory Split 16Mb (as no screen)
  • Update

Once changes have been made, issue the command:

sudo reboot

Install Gateway software

$ sudo apt-get install git
$ git clone https://github.com/thiseldo/RAK833-LoRaGateway-RPi.git ~/rak833-loragateway
$ cd ~/rak833-loragateway
$ sudo ./install.sh

Once installation has completed, the Pi will reboot. Make a note of the EUI that is presented at the end of the installation script. This is needed for the gateway setup on TTN.

Register gateway on The Things Network

Visit The Things Network console gateway registration page to setup your gateway.

Enter the gateway EUI, select I’m using the legacy packet forwarder , select the correct frequency plan to match the RAK833. In this case Europe 868MHz. The Router field is automatically populated. Once save, the gateway should show up and can be seen as connected in the overview.

Running the software

Once rebooted, the gateway software should start automatically. The GPS receiver should eventually get a fix, indicated by the red LED flashing.

To check the gateway is running, log onto the gateway using ssh and check. The output from the software is written to /var/log/syslog and can be viewed, as shown below:

Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: ##### 2019-04-30 12:08:53 GMT #####
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: ### [UPSTREAM] ###
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # RF packets received by concentrator: 27
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # CRC_OK: 3.70%, CRC_FAIL: 96.30%, NO_CRC: 0.00%
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # RF packets forwarded: 1 (5 bytes)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # PUSH_DATA datagrams sent: 2 (395 bytes)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # PUSH_DATA acknowledged: 100.00%
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: ### [DOWNSTREAM] ###
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # PULL_DATA sent: 3 (100.00% acknowledged)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # PULL_RESP(onse) datagrams received: 0 (0 bytes)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # RF packets sent to concentrator: 0 (0 bytes)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # TX errors: 0
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # TX rejected (collision packet): 0.00% (req:6, rej:0)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # TX rejected (collision beacon): 0.00% (req:6, rej:0)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # TX rejected (too late): 0.00% (req:6, rej:0)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # TX rejected (too early): 0.00% (req:6, rej:0)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # BEACON queued: 0
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # BEACON sent so far: 0
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # BEACON rejected: 0
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: ### [JIT] ###
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # SX1301 time (PPS): 812331781
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: src/jitqueue.c:448:jit_print_queue(): INFO: [jit] queue is empty
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: ### [GPS] ###
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # Valid time reference (age: 0 sec)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: # GPS coordinates: latitude aa.bbbbb, longitude c.ddddd, altitude ee m
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: ##### END #####
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: JSON up: {"stat":{"time":"2019-04-30 12:08:53 GMT","lati":aa.bbbbb,"long":c.ddddd,"alti":ee,"rxnb":27,"rxok":1,"rxfw":1,"ackr":100.0,"dwnb":0,"txnb":0}}
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: INFO: [up] PUSH_ACK received in 23 ms
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: INFO: Received pkt from mote: 260126ED (fcnt=34318)
Apr 30 13:09:23 loragateway2 ttn-gateway[5123]: JSON up: {"rxpk":[{"tmst":816067235,"time":"2019-04-30T12:08:55.735454Z","tmms":1240661354734,"chan":0,"rfch":1,"freq":868.100000,"stat":1,"modu":"LORA","datr":"SF7BW125","codr":"4/5","lsnr":9.0,"rssi":-44,"size":24,"data":"QO0mASYADoYBAW132jh3jlinzTdq4Nx4"}]}

If a GPS lock has been achieved then you should see valid coordinates in the output messages.

Enclosures

Now you have a working gateway, it is up to you how you want to package it. In the past we have used a basic aluminium extrusion with custom cut end-panels to produce an indoor gateway. For an external gateway, you will need a suitable enclosure with a minimum IP67 rating along with matching sockets. Other things to consider:

  • A larger antenna
  • Power Over Ethernet (POE) using a POE adaptor
  • WiFi instead of ethernet
  • Cellular connection for remote locations. Can get costly.

Now go build your network!