Making your own IoT The Things Network Gateway with a Raspberry Pi Zero


This article describes my process of creating a gateway for The Things Network based on a Raspberry Pi Zero W. As low-cost, yet feature rich as possible.

Parts overview (excluding casing)I’ve been following and (a bit) involved with The Things Network for a while now. The Things Network is a community powered Internet of Things (IoT) network, free to use by the community and also built by the community. Anyone with the right knowledge and a bit of money can create a gateway (antenna) and nodes (IoT connected devices). When you plug such a gateway to the internet and make a connection to The Things Network backend, you have expanded the network! The more people doing this, the stronger the network will become! A truly opensource and community powered network. available for anyone to use.

I’ve been one of the local community leaders of The Things Network for The Hague for some time, and we found out that it is actually quite difficult to start a community network like this. You need people, the network, connected devices and applications. But where do you start? A connected device needs a network and backend, people coming up with applications need to be able to understand and trust the network. So, to make a start, we are going to create the gateways first! When we have connected gateways, we have coverage and we can start to connect things!

What is a gateway?

A gateway is a device, connected to the internet, capable of sending and receiving lora packages. It acts as a bridge between devices and The Things Network. All gateways within reach of a device will receive the device’s messages and forward them to The Things Network. Typically a gateway runs on Linux, with a packet forwarding service installed. Read more about gateways in The Things Network documentation.

DIY Gateway

Parts

  1. Raspberry pi zero w (€11,-)
  2. 5V/2.5A Power supply (€10,-)
  3. 8Gb micro-SD card (€9,-)
  4. ic880a Concentrator board (€150,-)
  5. Antenna connector (€6,50)
  6. Antenna (€7,40)
  7. 7 FF Jumper wires Parts overview (excluding casing)The most expensive part is the concentrator board (which sends and receives the lora messages). All other parts you can also reuse. Total costs: €193,90 (incl. VAT). Cheap? No, but for this money you have a LoRa gateway with professional grade specifications (excluding the casing btw).

Installation

First of all: all credits go to: https://github.com/ttn-zh/ic880a-gateway This is a copy and paste of their instructions, with some details added.

Headless install of the Raspberry:

  • Download Raspbian Jessie Lite
  • Follow the installation instruction to create the SD card
  • Insert the SD card in your computer.
  • In the boot partition of the SD card, add to the bottom of the config.txt file dtoverlay=dwc2 on a new line, then save the file.
  • Add a new blank file calles ssh to the root of the boot partition. This is to enable SSH access.
  • Open cmdline.txt and insert modules-load=dwc2,g_ether after rootwait. This configuration is very picky with its formatting! Each parameter is separated by a single space (it does not use newlines).
  • Add wpa_supplicant.conf to the root of the SD card. When starting up, Raspbian will use this file to setup the wifi. This version of the raspberry only works with 2.4GHz networks (not 5GHz!). Use the following contents (with your own credentials) network = { ssid="ssidname" psk="password" }* Power up the raspberry. If all goes well you should be able to enter it using the command line via ssh pi@raspberry.local --> (password: raspberry) sudo raspi-config --> advanced: expand filesystem --> finish sudo apt-get update sudo apt-get upgrade sudo dpkg-reconfigure locales sudo dpkg-reconfigure tzdata sudo apt-get install git git clone https://github.com/ttn-zh/ic880a-gateway.git ~/ic880a-gateway cd ~/ic880a-gateway git -b checkout spi (Make sure you are in the SPI branch! ) sudo ./install.sh --> make a note of the Gateay IDConnecting the hardware

There are only 7 wires you need to connect, pretty simple:

https://github.com/ttn-zh/ic880a-gateway/wikiiC880a pin > Description > RPi physical pin 21 > Supply 5V > 2 22 > GND > 6 13 > Reset > 22 14 > SPI CLK > 23 15 > MISO > 21 16 > MOSI > 19 17 > NSS > 24

Wiring detailWiring detailsDIY casingPerfect!After installing all the components and putting them in the little cigar box, I now have a super portable wifi-based gateway! I use it for demonstration purposes on places where there is no TTN coverage (yet). I’ve set it up so that one of the wifi ssid’s is my mobile phone’s personal hotspot. That way I always have a connection.

Registration of the gateway with The Things Network

  • Login to thethingsnetwork.org Console
  • Click on Gateways -> register gateway
  • For now, we are using the ‘legacy package forwarder’ (see note below), so check this box
  • Enter your Gateway EUI (if is printed on start and end of the installer)
  • Enter any description
  • Select Europe 868Mhz as frequency plan
  • Select the correct antenna placement according to your plans
  • Confirm clicking Register gateway Congratulations, you now have a working Things Network Gateway, You Are The Network!

A note about the package software

At the moment there is is not really clear which package forwarder to use. The ‘legacy’ version we are using hereis working fine, but is not the latest version. The ‘official’ TTN version is currently ‘On Hold’. They are working on it, and will be public when ready … There is some discussion about it in the TTN Forum but at this stage it is unclear. So, we have to stick to the ‘old legacy’ version. Probably the update will be in the v3 stack that will hopefully be released at the upcoming TTN Conference in February 2018.

BTW, this is my gateway: eui-b827ebfffe331f45 Happy to serve your nodes :)

If you have any questions or remarks, please let me know through the Haagse Makers Community Forum: https://community.haagsemakers.nl/t/the-things-network-zelfbouw-gateway/218