31 August 2017 / Last updated: 31 Aug 2017

Deploying a gateway for The Things Network using resin.io

Execution time:
Difficulty:
Cost:
This article was written by Matthew Macdonald-Wallace of [Mockingbird Consulting](https://www.mockingbirdconsulting.co.uk" target="_blank). Mockingbird Consulting provides workshops on a wide range of topics and is committed to inspiring the next generation of engineers. Their "Internet of Threes" program helps organizations understand how people, places, and things are all part of a successful IoT project.
[The Things Network](https://www.thethingsnetwork.org/" target="_blank) (TTN) is a low cost, community supported alternative to 3G and WiFi. It is powered by [LoRaWAN](https://www.thethingsnetwork.org/wiki/LoRaWAN/Home" target="_blank), a new wireless data transmission technology, which combines long range with low power and bandwidth requirements, making it an ideal choice for the Internet of Things. The network can be expanded by anyone willing to deploy a gateway.
This guide explains how [resin.io](https://resin.io/" target="_blank) can be used to install and configure a LoRaWAN gateway based on a [Raspberry Pi](https://www.raspberrypi.org/" target="_blank) and the [IMST iC880A](https://webshop.imst.de/ic880a-spi-lorawan-concentrator-868mhz.html" target="_blank) gateway board. Be sure to check out this [full list of parts](https://github.com/ttn-zh/ic880a-gateway/wiki#ordering-the-parts" target="_blank) before moving on to these steps:
Step 1: Create an application
  • Log in to the [resin.io dashboard](https://dashboard.resin.io/" target="_blank) and create a new application. Make sure that you pick the appropriate model of Raspberry Pi—a Raspberry Pi 2 works perfectly well, but if you can stretch to a 3 then we'd recommend doing so.
Step 2: Configure the application
  • Once the application has been created, click on the Environment Variables button in the menu on the left of the screen:
  • Create the variables as follows:
Variable NameValue
GW_CONTACT_EMAILThe email address you want to show on the TTN map for your gateway
GW_REGIONThe region you should connect to for the TTN (EU/US/CN/AU/AS/KR)
GW_RESET_PINThe GPIO Pin used to reset the iC880A Gateway board (this should be set to 25 if you've purchased any of the interface boards)
GW_TYPEimst-ic880a-spi
SNMP_COMMUNITYOnly used if you want to enable SNMP for network monitoring
Step 3: Connect the device
  • From the main application page, click Download resinOS:
  • Flash the image to an SD card using a tool such as [Etcher](https://etcher.io/" target="_blank). Put the SD card into your Pi. Make sure the Pi can connect to the internet, either via ethernet or Wifi. Turn on the Pi.
  • While you wait for the Pi to make itself know to resin.io, you can [connect the hardware](https://github.com/ttn-zh/ic880a-gateway/wiki#putting-it-all-together" target="_blank) and [register your gateway](https://github.com/ttn-zh/ic880a-gateway/wiki#checking-connection-to-ttn" target="_blank) on The Things Network console.
  • After about 10 minutes, the Pi should show up on your dashboard with a random name. Click on the name, and you'll find yourself on the main screen for that device. Change the name if you need to, then click on Environment Variables again to set the device-specific settings.
Step 4: Configure the device
  • As with the application, the device is configured using environment variables. Make sure you set the following:
Variable NameValue
GW_DESCRIPTIONThe description of this particular gateway
GW_IDThe ID as configured in The Things Network console
GW_REF_ALTITUDEA fake altitude in meters above sea level if you're not using GPS
GW_REF_LATITUDEThe latitude of your device if you're not using GPS
GW_REF_LONGITUDEThe longitude of your device if you're not using GPS
SNMP_SYS_CONTACTThe SNMP System Contact if you're using SNMP
SNMP_SYS_LOCATIONThe SNMP Location if you're using SNMP
  • Save these variables, and you'll end up back at the main screen for the device.
Step 5: Push the application to the device
In order to turn the Pi into a gateway, we need to create a Dockerfile, install the packet forwarder, set it to start on boot, and configure it using the environment variables that we set in the preceeding steps.
Fortunately, [Mockingbird Consulting](https://www.mockingbirdconsulting.co.uk" target="_blank) has done the vast majority of this work already, so we can get up and running fast.
git clone https://github.com/mockingbirdconsulting/ttn-pkt-fwd-resin-setup.git
  • In the top right corner of the resin.io dashboard there is a text box that starts git remote add resin .... Use this information to add a new remote repository to your existing clone, pointing at resin.io's servers:
git remote add resin <USERNAME>@git.resin.io:<USERNAME>/<APPNAME>.git
  • Push the code from your repository to the resin.io servers:
git push resin master
  • You will see the code build, and if everything is successful you'll be presented with a unicorn letting you know that the build is complete:
Step 6: Verify
  • Change back to the resin.io dashboard and click on the device. You should see the status turn from green to blue as it updates with the new software, and then back to green as it comes online again. Logs are displayed in the console panel on the right of the screen.
  • Once the device shows as being online, switch to The Things Network console, and you should see the gateway as online, with a last seen time of within 60 seconds.
Congratulations!
If you've made it this far, then you're well on your way to deploying a fleet of gateways.
For each additional gateway that you deploy, just repeat steps 3 and 4—all new devices added to the application will automatically receive the gateway code when they connect. Any updates you push in the future will automatically be sent to all the gateways, upgrading them in place.
And when you're ready to tackle more IoT projects, we've got a [long list of tutorials](https://resin.io/blog/tag/tutorial/" target="_blank) to help you get started!
by Team balenaThe global group of product builders that brings you balena

Share this post