Internet of Things: Single Channel LoRa Gateway Build

Today the final outstanding item on the Single Channel LoRa Gateway Shopping List arrived in the post, and I now have everything needed to get my Single Channel LoRa Gateway up and running and posting data back to The Things Network. If you’d like to replicate the project follow the guide below to get your gateway up and running.

First lets get the hardware side of things sorted out. Take 8 female to female jumpers and chop off the connectors at one end, and then tin the wires ready for soldering. The raw ends will be soldered to the LoRa transceiver and the female dupont style connectors will be plugged into the Raspberry Pi’s GPIO header.

Solder a cable to each of the following pins; DI00, 3.3v, MISO, MOSI, SCK, RESET, NSS and the GND pin next to the MISO pin. Do not solder the GND cable to any other GND point of the board, it must be the one next to the MISO pin. I found I had to switch out my soldering iron tip to a very fine tip as the pads on the transceiver module are pretty small.

Once you have all the cables for the GPIO header connected to the RFM95W LoRa module solder an 8cm length of solid core bell wire to the ANT pin on the module, and another 8cm length of solid core bell wire to the GND pin next to the ANT pin, these wires should face opposite directions at a 180 degree angle and will act as a small dipole antenna.

Next connect up the LoRa transceiver to the Raspberry Pi GPIO header as per the following. Pin 1 is marked on the board.

RFM95W Raspberry Pi
3.3V 1
DI00 7
NSS 22
SCK 23

If you have not already loaded an OS onto your Raspberry Pi SD card you should do so now, I’ll be using Raspbian Jessie Lite although you are free to use any distribution that supports wiringpi. Once you have the OS on the sdcard connect up the Raspberry Pi to your network and boot it up. I’ll be configuring everything over SSH, if you want SSH to start by default on first boot place an empty file called ssh in the boot partition of the SD card, else on first boot SSH will remain in a stopped state.

After the Pi has booted up login and sudo up to the root user and then run the raspi-config utility:

rputt@loragw:~$ sudo su
root@loragw:~# raspi-config

From the menu select interfacing options and then select SPI, you need to ensure SPI is enabled prior to continuing configuration of the Pi.

If the configuration asks if you’d like to reboot say yes and reboot your Raspberry Pi. Next continue to install the wiringpi, gcc and git packages from your OS repository:

root@loragw:~# apt-get update
root@loragw:~# apt-get install -y wiringpi git gcc

Once the packages are installed we can continue to clone the single channel gateway packet forwarder from GitHub:

root@loragw:~# git clone

Now lets change directory into the repository we just cloned and check a few items in the source code:

root@loragw:~# cd single_chan_pkt_fwd
root@loragw:~/single_chan_pkt_fwd# vi main.cpp

In the file find the “#Define SERVER1” line and replace the IP address with, the IP in the repository is for an old The Things Network Router which has been retired, the IP provided in this blog is for, you can of course customise this value for a more appropriate host in your region. Next find the “uint32_t freq” line in the file and ensure it is set for the relevant frequency for your region, in the EU the frequency is 868100000 for 868.1mhz. Save the file and run the make command to build a binary from the code:

root@loragw:~/single_chan_pkt_fwd# make
g++ main.o base64.o -lwiringPi -o single_chan_pkt_fwd

Next run the single_chan_pkt_fwd binary and once it has done it’s initialisation press ctrl+c to stop its execution, if the hardware has been connected correctly and the software compiled successfully then you should see something like the following:

root@loragw:~/single_chan_pkt_fwd# ./single_chan_pkt_fwd
SX1276 detected, starting.
Gateway ID: ba:12:e3:ff:ff:42:4e:1b
Listening at SF7 on 868.100000 Mhz.
stat update: {"stat":{"time":"2017-05-06 14:37:10 GMT","lati":0.00000,"long":0.00000,"alti":0,"rxnb":0,"rxok":0,"rxfw":0,"ackr":0.0,"dwnb":0,"txnb":0,"pfrm":"Single Channel Gateway","mail":"","desc":""}}

Open a web browser and visit, if you already have an account login, if you are new to The Things Network sign up for a new account, once you are logged in go to the console, click the gateways button and the click register gateway.

Complete the form as per the following:

  • Protocol – Packet Forwarder
  • Gateway EUI – Copy the Gateway ID given when you first run the single_chan_pkt_fwd binary.
  • Description – A friendly name for your gateway.
  • Frequency Plan – Select the frequency plan for your region, this should match the frequency given when you run single_chan_pkt_fwd, if it does not then you probably have the wrong LoRa module for your region, you should order one with the relevant frequency for your region, running a LoRa module in the wrong frequency band may be illegal in your country.

You should end up with something that looks a bit like this…

Next click register gateway. The page will refresh and the gateway status should say “not connected”, now rerun the single_chan_pkt_fwd binary on your Raspberry Pi, the gateway should now check into The Things Network and the webpage should update to show a connected status and say it was last seen within the last 30 seconds or so.

That’s it, your LoRa single channel packet forwarder gateway is now up and running and capable of sending stuff like sensor readings to The Things Network. Remember there are a few limitations to running a single channel gateway compared to a full 8 channel gateway…

  • This particular implementation is uni directional, it can only receive packets from LoRa devices, not transmit data back.
  • The gateway only operates on 1 channel and 1 spread factor, in this case 868.1mhz and SP7, therefore you should update any LoRa node that you want to submit data from to only use the 868.1mhz channel not the usual 8 channel round robin.
  • If you like you can edit the channel it listens on and the spread factor by editing the frequency and spread factor in the main.cpp file and rerunning the make command.

Obviously when you logout of your Pi SSH session the single_chan_pkt_fwd binary stops running, you can either run this under a screen session or configure SystemD to run the binary as a service to make sure it continues running after you logout.

Whats next? Well, its all well and good having a LoRa gateway setup in your house, but without any data flowing over it’s pretty boring, I am currently waiting on another LoRa transceiver module to turn up (I ordered this one from Ali Express as they are much cheaper direct from China via Ali Express rather than ordering from a UK seller on eBay, but the delivery times suck) once that arrives I’ll continue to convert my ESP8266 DHT22 project to a LoRa DHT22 project and have it submit it’s readings over my LoRa gateway. Unfortunately until this arrives I have no real way of proving if my gateway does in fact work or not. Keep watching the blog for updates.

By @Robert Putt in
Tags : #internet, #iot, #electronics, #technology,