Building a single channel TTN Gateway

Posted on Sun 16 April 2017 in Hardware

I wanted to start playing around with LoRaWan devices. LoRaWan is a low-powered, long range RF protocol useful for transmitting tiny amounts of information from stuff like sensors and the like. The Thing Network (TTN) is a layer built on top of that, offering a standard back-end for routing messages from devices to wherever.

In order to start playing around with LoRaWan and The Things Network I need a gateway to relay the messages to the internet, and some nodes to generate some messages. A full gateway costs quite a lot, so I decided to try to build one myself. There are already a few guides available on the internet, and lots of firmware written for them.

The LoraWan specifications defines multiple frequency bands depending on which country you are in. Each frequency band is divided into multiple channels spaced 200 Khz apart. There is a minimum subset of channels in each band that must be supported. The specification requires gateways to be able to receive and send on all spreading factors and all channels, or at least all the minimum required channels for each frequency allocation. The single channel gateway can only receive on one channel, and only one spreading factor at a time. This is bad for LoraWan coverage, but works just fine for testing and development purposes. I will replace it with a full gateway later.

I did not do much of the coding for this project. Most of that comes from things4u's Single Channel LoRaWAN Gateway. Instead I chose to focus on the power supply, and just building the thing.

Gateway Design and Electronics

The first part of the gateway is the RF front end, which receives messages on different channels and different spreading factors. For my country (South Africa) this will be on 868MHz. These messages are then routed to the internet via ethernet, wifi, GSM, or any other method. A friend of mine, JP Meijers gave me some electronics hardware to get going with the gateway, so I'll be starting with that.

For the LORA frontend a HopeRFM95w is used, controlled via SPI from the ESP8266. It has an RF output and requires no further amplification or filtering.

For internet access the gateway uses an ESP8266-12. This chip also implements the communication with the HopeRF IC, and the Lora stack (as far as I know). To program the ESP8266 it is connected to a Wemos D1 mini adaptor board. This board makes it easier to program the ESP8266 chip, and provides a 3.3v regulator.

Gateway RF schematic

This shows the rough connections between the two ICs. Note that the wemos board also hosts the 3.3v regulator, as well as the usb connection and programming circuit for the ESP8266.

The antenna is a ground plane antenna, connected with a coax cable. I have no idea what the cable itself is.

I wanted to make the gateway solar powered, so that it would be completely wireless. It would also be fun to play around with solar panel. The solar panel is a 5W panel, which charges a 12v, 2.3Ah sealed lead acid battery. For the first iteration, the charging circuit is just an adjustable voltage regulator. This is probably very inefficient, so for a next version I'll try building a max power point tracking circuit.

Solar charging schematic

This was quickly hacked together over a weekend, so there are several issues with it. I'll design a better solar charging circuit sometime.

The gateway electronics on a breadboard

Building the gateway

I built most of the gateway over a weekend, and spent a few more days tweaking it and monitoring it. The body itself is built from a u-channel aluminium, fixed together with nuts and bolts and cable ties. I don't have access to a workshop, so pretty much everything was built on the balcony table, with a drill and a dremel. Since I'm renting the flat, it also had to be easily removable.

The gateway electronics on a breadboard Closeup of the station, showing the mechanical construction The completed gateway, on my balcony

The base is a piece of unsealed compressed wood, and is a temporary solution. It will swell and break from water during winter, so I'll replace it as soon as I can.

The electronics are stored inside a ice cream tub that is bolted to the aluminium. I have no idea how waterproof the container is, and I still have to cover the hole for the wires.

Programming the gateway

Monitoring

I'd like to monitor the battery voltage, so I installed Munin on an Raspberry PI. On the gateway itself the esp8266 hosts a webpage, which I changed to show the current voltage as well. A small script on the Raspberry PI fetches and parses the webpage, and munin logs it.

The station voltage over a week

The graph shows the station voltage for a week. There are a few sampling errors in the last few days. These actually all go down to 1.5v for one sample, then back up to about 10.5v. Currently I have no idea why this happens. It could be due to a bad connection, or the gateway resetting.

I'd like to add additional features to the power section, such as warnings for low voltage, or automatic cut-offs.

Update:

26 April 2017

The solar panel was defeated by a single rainy day. I noticed it wasn't charging, so disconnected it before it would discharge too much. An updated version of this station should have some automatic cut-off to prevent it from discharging the battery too much.