Setting Up a LoRa Gateway to View IoT Device Data

Overview

LoRa (Long Range) is a low-power long-range radio IoT technology that enables simple, secure worldwide deployment of sensors and other devices for a number of applications. In LoRa terminology, these deployed devices are called “nodes.”

At its core, a LoRa network (aka LoRaWAN) consists of nodes, gateways and LoRa network operators. Typically, nodes broadcast data to be picked up by gateways that forward the information to operator servers for processing.

When considering IOT app development project utilizing LoRa, it is important to keep in mind that these devices transmit at ISM frequencies (915 MHz in the U.S.), with an advertised line-of-sight range of up to 10 km or so. In urban settings, do not expect ranges of more than 2 km to 3 km.

Anyone can become a LoRa operator by deploying one or more gateways connected to a server, but there are a number of private and open community operators providing significant coverage in many countries.https://lora-alliance.org/in-the-news/lora-alliance-passes-100-lorawantm-network-operator-milestone-coverage-100-countries

Visit the LoRa Alliance website for an introduction to LoRa and available resources.

In this blog, we document the steps required to set up a gateway from scratch, register it with The Things Network and observe uplink data from a simple LoRa node. In future blogs, we will dive into details of the hardware and firmware/software for both LoRa nodes and gateways.

Select a Raspberry Pi-Based Gateway

There are a number of gateway products available, but we picked one based on the developer-friendly Raspberry Pi.

We picked the RAK7243 LPWAN Developer Gateway, purchased from Sparkfun. The gateway hardware consists of a Raspberry Pi 3 B+, with a RAK2245 concentrator module HAT that is installed over the Pi’s pins:

Raspberry Pi 3 B+, with a RAK2245 concentrator module HAT installed over the Pi’s pins

The kit is advertised to contain the following:

  • Raspberry Pi 3 B+
  • GPS shield
  • 915 MHz LoRa concentrator shield
  • Aluminum enclosure w/ heatsink
  • Power supply 5V, 2.5A
  • 16GB MicroSD card
  • GPS/GNSS antenna 1m with SMA
  • 915 MHz LoRa antenna 2dBi gain, 50 ohm

Unpack the Gateway

The gateway arrived nicely packaged:

Packaged RAK Gateway

The contents appeared to be as advertised, with the Pi and concentrator boards preinstalled in the rectangular enclosure:

RAK Gateway Kit

The enclosure has SMA connectors for the GPS and LoRa antennas. LTE is not supported in this kit (see the RAK7243C for LTE support), and the LTE antenna through-holes are plugged.

Setup

Introduction

This section documents our setup steps, starting from the delivered box contents. We considered our setup successful once the gateway was registered to The Things Network (TTN) and it properly forwarded packets from a known local node device to a TTN application.

Documentation

Sparkfun has some documentation on its product page, but a more complete set is available on RAK’s developer gateway product page.

Gateway Firmware Installation and Boot

Flash the 16 GB SD card

Installing the firmware is a matter of flashing the 16 GB SD card with the Raspbian image provided by RAKwireless. Initially, we tried flashing the card from a Windows 10 laptop but failed, so we switched to an Ubuntu machine for this.

Just for the record, these are the instructions for flashing from Windows:

  • Download the latest RPi Raspbian-based firmware image onto a Windows computer equipped with an SD card reader. There are two image zip files available. Use the one corresponding to the RAK7243, not the one for the LTE-enabled RAK7243C.
  • Unzip the downloaded file to get a Linux IMG file, e.g., RAK7243&RAK7244_based_on_Raspbian_OS_V4.2.0_20200311.img.
  • Install and launch the Etcher open source utility.
  • Insert the 16 GB SD card from the kit, which should be detected automatically by Etcher.
  • In Etcher, set the source to IMG file, the target to detected SD card, hit the Flash button and wait 2-3 minutes for flashing to complete.

Flash Complete failed device notification

Failure, checksums don’t match, see a forum post about this problem. Apparently, Windows 10 writes metadata that Etcher does not expect, and the workaround is complicated. Other tools might not have this problem.

To flash from a Linux (Ubuntu) machine, follow similar instructions:

  • Download the latest RPi Raspbian-based firmware image onto a Linux computer equipped with an SD card reader. There are two image zip files available. Use the one corresponding to the RAK7243, not the one for the LTE-enabled RAK7243C.
  • Unzip the downloaded file to get a Linux IMG file, e.g., RAK7243&RAK7244_based_on_Raspbian_OS_V4.2.0_20200311.img.
  • Install and launch the Etcher open source utility.
  • Insert the 16 GB SD card from the kit, which should be detected automatically by Etcher.
  • In Etcher, set the source to IMG file, the target to the detected SD card, hit the Flash button and wait 2-3 minutes for flashing to complete.
  • Eject the SD card.
Attach antennas, insert SD card and power up
  • Attach both antennas (LoRa and GPS). This is important since not having the antennas attached at power up can damage the boards. The following figure shows the antenna connections.

Antenna connections

  • Insert the flashed SD card. The card slot is near the bottom of the enclosure under the antenna connectors. When inserting the SD card, take care not to push it through the horizontal gap between the SD card slot and the enclosure. If this happens, the gateway must be disassembled to recover the card.
  • Connect the power supply to the gateway’s micro-USB port.
  • Turn on the power supply.
  • Verify blinking LEDs at the bottom of the enclosure under the GPS antenna.
Test Wi-Fi connectivity
  • Verify that the gateway appears on Wi-Fi as an AP with network SSID of the form Rakwireless_XXXX.
  • Connect to the gateway’s network, using the default Wi-Fi password “rakwireless”.
  • Check the Wi-Fi settings for the gateway on the connected computer. For example, on a Windows 10 PC, the following information shows the gateway with address 192.168.230.1. The 192.168.230.225 in the figure is the PC’s address on the gateway’s network.

Wi-Fi Connectivity Figure

  • Check that logging into the gateway via ssh is available over this connection. The default user and password are: “pi” / “raspberry”.
Add the gateway to an Ethernet LAN

The gateway ships with a fixed IP address 192.168.10.10 when connected over Ethernet and can be connected to a properly configured PC using this address, but in most cases, it is best to have the gateway obtain its address from a managed network. To do this:

  • Log in to the gateway via ssh over Wi-Fi.
  • Make a backup copy of existing /etc/dhcpcd.conf.
  • Comment out the lines in dhcpcd.conf that create the hard-coded address (ignore the warning not to modify the 5 lines):

Code Modification Warning

  • Reboot the gateway.
  • Connect again over Wi-Fi and run “ifconfig” to check the new LAN-provided DHCP address. Modify the LAN router as needed to make the new address permanent for the gateway.
  • Verify that ssh works over the IP address provided by the LAN’s DHCP server.
  • At this point, it should be possible to log in with ssh with either the Wi-Fi or the Ethernet connection.

Configure Gateway for The Things Network (TTN)

We configured the gateway to work with the TTN community LoRa operator, which supports no-cost LoRa gateway registrations.

Configure the Gateway’s LoRa Concentrator for TTN
  • ssh to the gateway and run the gateway’s configuration tool: sudo gateway-config.
  • Select the concentrator menu option and choose “Server is TTN” and the correct channel plan for the gateway’s location. In our case, we chose the US_902_928 channel plan.

RAK Gateway Configuration Options

Server Plan Configuration

Channel Plan ConfigurationAfter confirming these settings, the configuration tool reported back with a message indicating that the server configuration had been changed and the packet forwarder had been restarted.

Register the Gateway on The Things Network (TTN)

The gateway EUI

To register the gateway with TTN, first obtain the gateway’s ID:

Gateway ID

In this example, the ID (EUI) is B827EBFFFE5E9AA5 and corresponds to the MAC address of the LoRa module in the gateway. It is a unique identifier, which is required to register the gateway with any LoRa network.

Create a TTN account and register the gateway
  • Go to www.thethingsnetwork.org to create an account.
  • Log in to the TTN account and follow instructions for registering the gateway. Make sure to check the box “I’m using the legacy packet forwarder.” Note: one account can support multiple gateways.

Gateway Registration

Wait for TTN to indicate a successful connection with the gateway

Immediately after registration, TTN will indicate “no connection”:

Gateway Overview No Connection

Troubleshoot the connection to TTN server

If TTS continues to show a disconnected status, then check the TTS network. In our case, the TTS network looked fine, so we tried to establish a TCP connection from the gateway to the server’s MQTT port, using

[email protected]:~ $ nc -v bridge.us-west.thethings.network 1883

and failed initially. Turns out port 1883 was blocked in our router, and the same command was successful after unblocking the port.

Note: the host name “bridge.us-west.thethings.network” was obtained from the registration, and 1883 is the standard port for the MQTT protocol used by gateways to communicate with TTS.

Locate the gateway in TTN’s map

The TTN site includes a world map of all registered gateways. The following screenshot shows our gateway (Gunbarrel), as well as another gateway we have previously set up at Cardinal Peak’s main office. As a whole, Colorado currently has about 20 gateways registered to TTN, North America has approximately 750 registered gateways, and Europe carries the bulk with over 7,000. The worldwide active total for TTN is a little over 10,000. These numbers are only for TTN, so don’t include gateways for other LoRaWAN operators.

Gateways On Map

Mystery: TTN doesn’t show the right GPS coordinates, but the GW logs indicate the GW is sending proper GPS:

GW Logs

Gateway Logs

The gateway writes logs in /var/log/syslog. The screenshots below show logs (grepped for concentrator packets) at the Gunbarrel (left log) and CP office (right) gateways. As expected, the office gateway, with its larger 5.8 dBi outdoor antenna, shows more packets (about 5-10 times) than Gunbarrel, which has the small 2dBi antenna provided in the kit.

/var/log/syslog

Observe Data from a Nearby Node

For our test node, we used a SparkFun Pro RF LoRa 915MHz device that was previously registered with TTN and associated with a simple test application owned by Cardinal Peak. A future blog will discuss how to configure and register a device with TTN, and how to securely associate it with an application. For now, we are simply interested in verifying that the data from this particular device can make it to the application via our newly created gateway.

For this test, the device and the gateway were placed within a few feet of each other. The device was powered over USB.

To look at the node device data, we logged into the TTN account that owns the application, navigated to the application’s console and, from there, moved to the device’s data page:

This page displays uplink data in real time, and we can see that the device sends a payload every six to seven seconds. To verify that the data was flowing through our gateway (and not being picked up by the gateway at Cardinal Peak’s office), we shut down the gateway, restarted it, and observed how the flow stopped and resumed accordingly. In the display above, we see gaps after counter numbers 374 and 398, which correspond to the intervals where the gateway was shut down.

Conclusion

While there are myriad steps involved in setting up a LoRa network gateway from scratch, registering it with The Things Network and observing uplink data from a simple LoRa node, it is a crucial step in integrating IoT technologies into the embedded devices and applications that drive our world forward.

If you have any questions or want to tap our LoRa expertise for your next project, let us know!

Previous
Next