Skip to main content
shopping_basket Basket 0
Log in

Building a Raspberry Pi Powered LoRaWAN Gateway


Using a Raspberry Pi 2 + iC880A to build the first gateway for Things Network Calderdale

Last month I wrote about The Things Network (TTN) — a free and open LoRaWAN powered data network for IoT applications — and how we've started a community in Calderdale, with our immediate priority being to use this to support a crowdsourced flood sensor network.

This post picks up where the previous left off, taking a look in more detail at the hardware used to construct a DIY gateway (a.k.a. an “access point” or “base station”), together with the software, its configuration and initial testing.

Note that there are numerous off-the-shelf LoRaWAN gateways available, along with simpler/cheaper DIY solutions. However, the approach taken here provides a good balance of cost, flexibility and performance, while enabling us to also learn a bit more about how LoRaWAN works.



The front-end is provided by an IMST iC880A LoRaWAN “concentrator” board. This integrates two Semtech SX1257 transceiver ICs plus an SX1301 baseband processor. A combination that is able to emulate 49x LoRa demodulators, with 10 parallel demodulation paths, in order to receive up to 8 LoRa packets simultaneously sent with different spreading factors on different channels.

This may sound complex and it's thanks to LoRa's modulation format that it is able to achieve such incredible ranges with remarkably modest transmit power levels, while also supporting thousands of nodes per gateway. In practice there are details you probably don't need to worry about, although radio and MAC layer configuration is possible and may be required in certain circumstances.

A Raspberry Pi 2 Model B was selected to run the gateway software and this interfaces with the concentrator via SPI and a very simple breakout/baseboard constructed from perfboard. Connection details for the iC880A can be found in the associated documentation and note that in addition to SPI connection, a standard GPIO pin on the Raspberry Pi is also required for resetting the module.

The boards were housed in a diecast aluminium enclosure to provide RF Screening, which was drilled for a power socket, switch and LED, and chain-drilled/filed to provide access to Ethernet.



The latest Raspbian Jessie Lite image was downloaded and written out to a Micro SD card. Upon then booting the Raspberry Pi, this was followed by the usual sequence of:

$ sudo apt-get update
$ sudo apt-get upgrade

And also:

$ sudo apt-get install git wiringpi

Git is required for cloning the software sources and WiringPi to provide a simple mechanism for toggling the GPIO pin which resets the concentrator board.

The hostname was changed by editing /etc/hostname, along with the corresponding entry in /etc/hosts.

The Raspberry Pi configuration tool was run next with:

$ sudo raspi-config

To enable communications via the SPI bus, Advanced Options (9), followed by SPI (A6) was selected, before then selecting to enable SPI and the kernel module to load at boot time.

Since we were using a 16GB Micro SD card, the raspi-config tool was also used to expand the root filesystem to fill this, before then rebooting.

The documentation from IMST suggests building the LoRaWAN software from the reference sources provide by Semtech. However, forks of this with various updates are being maintained by The Things Network under their GitHub organisation.

The Things Network Zurich have gone one step further by providing an automated installer. Although I wasn't happy with a few of the steps that this performs, such as renaming your Raspberry Pi to a generic name (ttn-gateway) and building WiringPi from source, instead of simply using the package available from the Raspbian repositories.

So instead I used the script as a crib to manually installing, and performed the following:

  1. Got the SPI branch of the automated installer (git clone, git checkout...)

  2. Cloned and built the LoRa gateway application

  3. Cloned and built the packet forwarder application

  4. Created the bin directory, plus the symbolic link for poly_pkt_fwd and copied across the global_conf.json file

  5. Omitted creating local_conf.json or resetting the gateway ID

  6. Copied to the bin directory and set up the packet forwarder as a service

Note that when building the gateway application:

  • The libloragw/library.cfg file must be updated so that PLATFORM is set to imst_rpi (see the corresponding sed line in

  • Debugging can be turned on by setting the appropriate variable(s) in libloragw/library.cfg

The ability to turn on debugging for SPI, device registers and the HAL etc. can prove invaluable if the application does not successfully start once configured.

Note also that if you want to use the provided service description file — to enable starting the application at boot time — you need to make sure that software and config has been moved to the expected locations under /opt/ttn-gateway, else modify this as appropriate.

At some point I'll probably clone the installer repository and modify the script slightly to suite my own tastes. Although what would be much better is to have the gateway and packet forwarder applications properly packaged and installable via a Debian repository and apt-get, with config held in a more suitable location, such as /etc/ttn/, instead of alongside executables in the bin directory.

At this point I was able to run up a utility that tests transmit and in doing so confirm operation of SPI and the software.


Although I should note that the spectrum analyser had a small antenna connected to its port and was not directly connected, so ignore the level measurement. Also, at this point the gateway was running from a power supply which was not delivering sufficient current, so the transmit burst may look a little different when the concentrator is provided with sufficient power.



So now we have two pieces of software built, lora_gateway and packet_forwarder. But what do these provide?

lora_gateway is mainly a library — libloragw.a — that provides the foundations for building a gateway, which is configured via the library.cfg file for the particular hardware platform and interface with the computer running the software, along with optional debugging etc. Helper programs are also provided that enable you to log received packets and test SPI and transmit.

packet_forwarder then builds on top of the library (a.k.a. “driver” or “HAL”) to forward packets that are received over the air interface, via an IP/UDP link to a host. In addition to uplink operation, the gateway also supports sending downlink (to nodes) packets generated by the server, e.g. for time synchronisation. Note that at this point is does not support a general downlink data service.

At the time of writing there are actually four packet forwarder applications:

  • basic. As the name suggests! Simply forwards received packets over UDP to a host.

  • gps. Adds support for a aGPS receiver, for absolute time sync and gateway localisation.

  • beacon. As with gps, but adds support for sending beacon packets for node synchronisation.

  • poly. As with beacon, but adds support for multiple servers and other features.

The poly_pkt_forward application appears to be the preferred one, even if you do not require some of the more advanced features, do to a reported increased stability.

The packet forwarder applications are configured by a generic global_conf.json file, which provides the bulk of the configuration required, including that for the transceivers, radio channels, MAC and network key etc. Site configuration is then provided via local_conf.json (as pictured above), which allows for additional settings and default ones to be overridden. In the main these are:

  • Gateway ID. This is constructed from the prefix FFE plus the Ethernet interface MAC address on the Raspberry Pi.

  • Contact e-mail and description.

  • GPS coordinates and altitude. Enabling fake_gps as a receiver module is not fitted at this point.

  • Server address and ports. Those of the server operated by The Things Network.

On this last configuration point, note that you could equally configure details for your own server.

With configuration completed, the packet forwarder could be started manually with:

$ ./poly_pkt_fwd


Once satisfied that the gateway packet forwarder would successfully start up, the Pi was shut down.

Site installation


The gateway in its diecast aluminium enclosure was fitted inside a larger, steel, IP rated enclosure that is wall mounted. This includes plenty of space for a future wideband SDR receiver which can be used for spectrum monitoring. Din rail is fitted towards the bottom of the cabinet.


Currently fitted to this we have mains distribution and a 5V PSU with plenty of spare capacity, along with further space for additional PSUs should we later require other voltage rails.


At the top of the cabinet we have surge arresters fitted before the aerials, with heavy 10mm2 cable connecting these to a dedicated earth rod.


On the interior we can see two tiny coaxial cables feeding through for the 868MHz and GPS aerials. To the left of which is an N type feedthrough for the 25-3,0000MHz antenna. With a spare to the left of that, which could be used in the future to connect that antenna, via a coaxial relay, back out to another feeder which runs into the workshop, enabling use with other equipment.



With the gateway installed it was time to put this to the test. At the present time the only complete LoRaWAN node we have a is prototype of the new sensor from Flood Network, so we decided to power this up and see if we could find it via The Things Network API. Happily, we could!


What next? Well, we plan to:

  • Work with Flood Network to get a few more sensors online

  • Map coverage of the first gateway

  • Work with the local hackerspace, Bridge Rectifier, to get a 2nd gateway online

Andrew Back

Open source (hardware and software!) advocate, Treasurer and Director of the Free and Open Source Silicon Foundation, organiser of Wuthering Bytes technology festival and founder of the Open Source Hardware User Group.


May 14, 2021 13:45

Hi Andrew,
I have a similary project.
For surge protect my GSM module and 4G data box:
Please, what's yours references surge arresters ?
How choice your surge arresters ?
Thanks in advance

0 Votes

July 30, 2020 09:08

Great project!

0 Votes

December 4, 2018 08:50

Thank you very much!

I had to to the following actions in addition (or did I miss something?)
- add user to group gpio in order to be able to toggle reset pin:
sudo usermod -a -G gpio ttn
- change number of reset gpio to 17:
sudo nano /opt/ttn-gateway/bin/
(line 4: change value to 17)

0 Votes

[Comment was deleted]

March 5, 2018 15:02

Hi, nice development here, thanks for sharing, I have a question . or couple, actually.
Did you test distance from your gateway? Hight of antenna? and any stressing test regarding connections? any data on this subject, please. And finally stability? how would you rate it? is it stable, was up , running for some time? Thanks a lot in advance.

0 Votes

January 11, 2018 08:48

@Verfacil I'm afraid we replaced our gateways some time ago and so I've no idea what the current status of software support is. I'd recommend contacting IMST.

0 Votes

January 9, 2018 08:38

Andrew. I cannot believe how stuck I am with this! I built the gateway (pi3 & ic880a) and used the TTN automated files for set up. I have even successfully created the "gateway_remote_config" .json file and it was merged okay (no idea how I achieved that!. I just don't know how Github actually works and your line "So instead I used the script as a crib to manually installing, and performed the following" just sent me in a spin! I am guessing I don't know enough about Pi software either. Is there a real idiot guide (step by step) for configuring a gateway as I am keen to configure it but it's becoming depressingly hard! :)

0 Votes

February 7, 2018 11:11

@Verfacil Did you manage to get some help?

I installed and setup a Raspberry Pi 3, using these instructions

What I found was that when I tried to download the software from Github, it failed.

What I discovered is that you have to install Git onto the Raspberry PI 3, before attempting to follow the instructions for downloading the software FROM Github (as its not already on the PI).

Type this to install the Git software onto the PI:

sudo apt-get install git

Once you have installed Git, then follow the TTN software installation instructions, for download from Github.

If you need any more help, let me know.

Craig Miles

February 12, 2018 08:35

@yeswayltd - Hi Craig, saw your comment above and I hope you don't mind me jumping in. I've built and set up the gateway following the instructions you provided the link for. I've also added the config file to GitHub at but when I go to the TTN console the gateway shows as not connected. I did note this on the remote config repository page "The content of the file should be your local_conf.json" so I'm wondering if to get started I have to create this file or at least modify what's written by default. I'm newish to Linux and RPi so somethings others take for granted, like issuing instructions via the command line I need a bit more help with (but I get there in the end). Any thoughts/suggestions would be much appreciated. Thanks in advance, Steve

[Comment was deleted]

[Comment was deleted]

October 25, 2017 10:00

Great writeup, one of the most detailed I've seen so far. Hope to see more info on how the gateway is performing since last year and any challenges encountered.

0 Votes

August 18, 2017 07:51

Do you have a link for the mains / DC distribution din rail sections? Very neat way to do it.

0 Votes

April 12, 2017 14:18

Hi Andrew, great write up - I used it to build my own gateway. Question: How do you define the legal status of your gateway? As far as I can see it isn't CE certified and therefore is illegal to operate in the UK.

0 Votes

[Comment was deleted]

March 10, 2017 09:58

Really nice! I hope to correspond soon after my similar project is underway.

0 Votes

[Comment was deleted]

[Comment was deleted]

August 31, 2016 11:27

Hi there

Nice integration. Could you tell which surge arresters you used? Did you use any other protection matters?

0 Votes

April 21, 2016 09:59

My email is

0 Votes

April 21, 2016 09:58

Hi, Please anyone assist me to set up and test a LoRaWAN gateway. I have bought everything needed, Raspberry pi, and ic800a. But trying to follow up the instruction given all over I can prove if I have done the correct thing because I cant see how to confirm its working.

0 Votes

April 1, 2016 08:52

Brilliant write-up, and it looks like a top job!

0 Votes

March 29, 2016 00:46

Hi there!

Awesome description of the process of building this! Also great to see that our installer script served at least as inspiration! I took advice from you and changed it to make the hostname changing optional and switching to wiringpi packaged instead of built from source.


0 Votes
DesignSpark Electrical Logolinkedin