Contributing an IoT LoRaWAN Raspberry Pi RAK831 Gateway to The Things Network

LoRa and LoRaWAN is getting the de-facto wireless IoT network in my area. No surprise that traditional telecom providers like Swisscom trying to monetize the ‘Internet of Things’ area. Luckily there is an open and free alternative: https://www.thethingsnetwork.org/. Volunteers, enthusiasts and members in the different TTN communities build gateways and offer free LoRaWAN network access. I wanted to contribute to that grassroots movement with building my gateway, providing LoRaWAN access to my neighborhood.

LoRaWAN TheThingsNetwork Gateway

LoRaWAN TheThingsNetwork Gateway

TheThings Network LoRaWAN Gateways in Switzerland

TheThings Network LoRaWAN Gateways in Switzerland

RAK831 Semtech SX1301 LoRaWAN Gateway Module

RAK Wirless sells the RAK831 module (https://www.rakwireless.com/en/WisKeyOSH/RAK831).

Application Diagram

Application Diagram (Source: Rakwireless.com)

As host I’m using a Raspberry Pi which then will be able act as multi-channel LoRaWAN gateway supporting 10 channels (8 downlink, 1 uplink and 1 FSK channel). The GPS module is used as timestamp interface for the SX1301.

The Kit

I ordered my RAK831 868 MHz kit from AliExpress without a Raspberry Pi. I’m using it with a Raspberry Pi 3 Model B V1.2.

RAK831 Kit Content

RAK831 Kit Content

The LoRA and the GPS module are connected with an antenna cable:

RAK831 Modules

RAK831 Modules

I opted for the kit with the external GPS antenna and the aluminium enclosure with heat sink. To fit the LoRa Gateway module into the case, the two sides brackets of the gateway PCB need to be removed.

💡 Never (never!) power the gateway without the antenna attached, otherwise it might burn the transceiver!

Raspberry Pi Setup

I assume basic knowledge about how to setup a Raspberry Pi: set up your system with a recent distribution, see https://www.raspberrypi.org/

I recommend not to fully assemble the enclosure during software installation, as otherwise the LED of the LoRa board cannot be monitored:

Pi with Gateway

Pi with Gateway

Because the Semtech chip produces a lot of heat, that blue heat transmission material is placed on top of the heat-sink via’s to transmit the heat to the enclosure.

Enable SPI

The Raspberry Pi gateway software communicates with the LoRa transceiver. The SPI peripheral is not turned on by default. To enable it, do the following.

  1. run ‘sudo raspi-config’
  2. Select ‘Interfacing Options’

    Interfacing Options

    Interfacing Options

  3. Select ‘SPI’:

    SPI

    SPI

  4. Select ‘yes’ to enable SPI:

    Select SPI

    Select SPI

  5. Confirm as well with ‘yes’ if it ask to automatically load the kernel module.
  6. Then exit and finish the dialog
  7. reboot

Installing Gateway

First, get a general update:

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

Next, cd to the user account

cd ~

Clone the gateway from git:

git clone https://github.com/ttn-zh/ic880a-gateway.git ~/ic880a-gateway

cd into that directory:

cd ic880a-gateway

Reset Pin

By default, the gateway is using pin 25 to reset the gateway. This was the problem why I was not able to use the gateway out of the box  and took me a while to realize. So: change the reset pin setting from pin 25 to 17! There are actually two scripts: one in ~/ic880a-gateway/start.sh and one in /opt/ttn-gateway/bin/start.sh. Both files need to be modified!

The one in the ic880a-gateway folder can be modified right away and is copied to /opt/ttn-gateway/bin/start.sh durinig inistallation.

Reset pin number in start.sh

Reset pin number in start.sh

Setup

Run the script inside the ic880a-gateway folder:

sudo ./install.sh

It shall report the EUI number: write it down or copy it:

EUI

EUI

Now stop here for a while. First we need to setup the TTN side…

Register for a The-Things-Network (TTN) account at: https://account.thethingsnetwork.org/register

Go to the ‘Console’ area on your TTN account where you can register a new gateway. Enter all the information, but make sure you select ‘I’m using the legacy packet forwarder’. And here we have now to enter that EUI number we have noted down from the previous step:

Legacy Packet Forwarder

Legacy Packet Forwarder

Fill out the other fields, e.g.:

Register Gateway

Register Gateway

Remember the GPS coordinates as you will need them on the Raspberry Pi for an initial setup, then proceed with the registration with pressing ‘N’. then enter all the information:

Continue Setup

Continue Setup

The information entered gets stored in /opt/ttn-gateway/bin/local_conf.json. In that same folder there is a global_conf.json which configures the other parts of the gateway.

At the end, the machine gets rebooted.

Don’t forget to verify the reset pin number in /opt/ttn-gateway/bin/start.sh!

Reboot and check the logs with:

systemctl status ttn-gateway.service

It should report something like this:

Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: INFO: [down] for server router.eu.thethings.network PULL_ACK re
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: ##### 2019-02-24 16:20:29 GMT #####
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: ### [UPSTREAM] ###
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: # RF packets received by concentrator: 0
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: # CRC_OK: 0.00%, CRC_FAIL: 0.00%, NO_CRC: 0.00%
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: # RF packets forwarded: 0 (0 bytes)
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: # PUSH_DATA datagrams sent: 1 (241 bytes)
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: # PUSH_DATA acknowledged: 100.00%
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: ### [DOWNSTREAM] ###
Feb 24 17:20:29 LoRaWanGW ttn-gateway[356]: # PULL_DATA sent: 3 (100.00% acknowledged)

At the end and with yet another reboot, the RX LED shall be now on:

Success LED is ON

Success LED is ON

Check the status of the gateway in the TTN Router console:

Gateway Overview

Gateway Overview

Congratulations, you have a LoRaWAN gateway!

Monitoring UDP Port 1700

A good way to check that everything is working is to use ‘tcpdump’. If not already installed, install it with

sudo apt-get install tcpdump

Then I can monitor the traffic with

sudo tcpdump -AUq port 1700

which should show something like this:

tcpdump

tcpdump

Another good way to verify the system is to check the syslog:

sudo tail -f /var/log/syslog
invalid gps time

invalid gps time

As seen above, my GPS is not configured properly, so this is something I have to cover next.

GPS

For me the GPS module was attached to ttyS0. Use the following to see the NMEA messages coming in:

sudo cat /dev/ttyS0

Which should show some GPS messages coming.

What is missing is that the messages are consumed to the gateway. For this I have to edit the /opt/ttn-gateway/bin/global_conf.json configuration file. Below what I had installed:

original GPS configuration

original GPS configuration

I changed this to

/* GPS configuration */
"gps_tty_path": "/dev/ttyS0",
"fake_gps": false,
"ref_latitude": 10,
"ref_longitude": 20,
"ref_altitude": -1,

The other thing is that I have to disable the login shell on the UART. This is a setting in the configs:

sudo raspi-config

then Interfacing Options:

Interfacing Options

Interfacing Options

Then select Serial:

Serial config

Serial config

Disable the Login Shell:

login shell disabled

login shell disabled

With the Serial Port Hardware Enabled:

serial hw port enabled

serial hw port enabled

Confirm and reboot:

Login shell disabled and interface enabled

Login shell disabled and interface enabled

And now I have a working GPS 🙂

Working GPS

Working GPS

Summary

Contributing to an open source and community network is fun and a learning experience the same time. The gateway is now working for several days and is handling LoRaWAN packets from my neighborhood. A next step is to attach a long fiberglass antenna and put that gateway with a fiberglass antenna on top of my house for a larger coverage 🙂

Happy LoRaWANing 🙂

Links

 

12 thoughts on “Contributing an IoT LoRaWAN Raspberry Pi RAK831 Gateway to The Things Network

  1. thanks for the interesting post!
    I would be interested to learn how much it actually is to operate a LoraWan GW. Do you have a rough overview how much money you overall invested in the GW and how much power this consumes in operation? (the statement about the cooling made me suspicious)

    Like

    • I did not make any power measurement, but I’m using a ‘normal’ RPi 5V/2A power supply.
      AS for the RAK831 Gateway: the Kit (GPS board with external antenna, SX1301 board with antenna plus the metal enclosure) was $215 (incl. shipment).
      So you have to add the Raspberry Pi (with Power supply), say in the range of $40.
      I hope this helps?

      Like

      • Erich, thanks for your reply – it fully answers my question. I wanted to understand what investment it means to run a gateway.
        I am curious to learn what antenna solution you will end up with – looking forward to a follow-up post there!
        Thanks for sharing all this!
        Michael

        Like

        • Hi Michael,
          I ordered the 40cm RAK glass fiber external antenna from their store and it is on the way. There might be better (and longer) antennas, but I thought I give this one a try.
          Erich

          Like

  2. Pingback: Tutorial: RAK813 LoRaWAN+BLE+GPS Sensor Node with Eclipse IDE | MCU on Eclipse

  3. Pingback: Log2Ram: Extending SD Card Lifetime for Raspberry Pi LoRaWAN Gateway | MCU on Eclipse

  4. Pingback: Reverse Engineering of a Not-so-Secure IoT Device | MCU on Eclipse

  5. Pingback: Building a Raspberry Pi UPS and Serial Login Console with tinyK22 (NXP K22FN512) | MCU on Eclipse

  6. Hi Erich,

    Thanks for the great article, with lots of very useful detail.

    One very small suggestion, is that you change “Monitoring TCP Port 1700” to instead be “Monitoring UDP Port 1700”, as the traffic from the gateway is UDP to port 1700 of TTN’s server. (Maybe TCP also gets used under some circumstances, but I haven’t seen that yet… only UDP).

    Chris

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.