Introduction
Locating the Gateway
Internet Access Issues
Things Uno Setup
Making the Things Uno Portable
A Case for the Things Uno
Range Testing
Next Steps
Introduction
We are working to set up an environmental sensor network in the city of Charlottetown, Prince Edward Island, a small community of 36,000 people off the east coast of Canada. We are, right now, a small group of people of diverse backgrounds, operating as an ad hoc advisory committee with City Hall. We're inspired, in part, by the efforts of a similar group in Amersfoort, NL under the Meetjestad.nl banner.
This is the story of installing a Things Network Gateway, setting up a test sensor using a Things Uno, testing the range, and optimizing the location of the gateway's location and antenna. It's work in progress.
Locating the Gateway
To find a location to test our gateway, we looked for someplace that was high off the ground, centrally located, had Internet access and power available, and had a willing host.
Charlottetown City Hall met all of these characteristics. Located in the centre of the downtown core, it has a tall bell tower that, while not the tallest structure in the city, was relatively easy to access. And, as City Hall is a partner in this project, we had a willing host.
The Bell Tower & Fall Protection
It turned out that to be able to access the top of the bell tower, reached by a precarious-looking ladder, required that we have "fall protection" training, which we didn't have.
While we might later be able to make arrangements to have professionals (or someone else, with this training) install into the tower, we decided, to allow for easier access during testing, to locate the gateway lower down, in an office space on the top floor of City Hall.
The Backup Location
The backup location was in a window on the third floor of City Hall, approximately 9 metres above street level, facing southeast over the downtown core:
The location is in the accounting office of City Hall, and provided us with a nearby power outlet and Ethernet jack to provide Internet access to the gateway.
Internet Access Issues
To connect The Things Gateway to the Internet we had three options at City Hall: a guest wifi network, an internal wifi network, and an internal wired network.
Trying the Wifi
We were unsuccessful, despite multiple attempts, in getting The Things Gateway to connect to either the guest or internal wifi network: the SSID showed up on the gateway setup page, we could enter the WPA password, but LED 2 on the gateway stayed in "fast flashing" mode, which, it says here, means that it could not connect to the Internet.
Trying the Wired Network
Once we switched to a hardwired Ethernet connection to the City Hall network, we had more success: the gateway connected to the Internet, but then became stuck on slow-flashing LED 4, indicating it could not connect to The Things Network via MQTT.
Firewall Issues?
We learned from this forum post that the source of this issue may be outbound traffic being blocked on necessary ports on the City Hall network, namely:
1) 1700/udp (legacy/Semtech, incl “connection tracking” in iptables)
2) 1883/tcp + 8883/tcp (MQTT forwarder) (any other name for this?)
3) 1900/tcp + 1901/tcp (Go forwarder aka the “new packet forwarder” as it’s named in eg.
Using telnet on a MacBook Air connected to the same network, we were able to confirm that the firewall was, indeed, preventing the required outbound traffic; for example:
telnet test.mosquitto.org 1883
did not result in a successful connection.
So we sent an email to the City Hall IT department, as follows:
As we discussed this afternoon, to be able to send sensor data (received wirelessly from sensors around the city) to The Things Network, where it can be used, the gateway we’d like to install in City Hall needs to be able to communicate on ports other that the standard ports 80 and 443 that the City Hall firewall is set up to allow.
Specifically, the following is required of the firewall:
1. Port 1700/UDP (including “connection tracking”).
2. Ports 1883/TCP and 8883/TCP.
3. Ports 1900/TCP and 1901/TCP.
For all of the above, it’s only outbound traffic that needs to be allowed — there’s no need for traffic from the Internet inbound to be allowed in to the City Hall network.
The required firewall changes were made quickly, and the next morning we were ready for testing again.
Success!
With the ports on the firewall open, we were able to get The Things Gateway connected to both the Internet (through a wired connection to the City Hall network) and to The Things Network, confirmed both by the state of the LEDs on the gateway, and by The Things Network console:
Things Uno Setup
With The Things Gateway in place and operating properly, we were ready to test the LoRaWAN part of the setup; our test device was a Things Uno (an Arduino Leonardo with a LoRaWAN chip on it).
Arduino Script
Our first step, after confirming that the Things Uno was working properly and obtaining its Device EUI, was to write a script, using the Arduino IDE, to broadcast a single-byte "ping" every 10 seconds. The script looks like this:
#include <TheThingsNetwork.h>
// Set your AppEUI and AppKey
const char *appEui = "XXXXXXXXXXX";
const char *appKey = "XXXXXXXXXXX";
#define loraSerial Serial1
#define debugSerial Serial
#define freqPlan TTN_FP_US915
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
void setup()
{
loraSerial.begin(57600);
debugSerial.begin(9600);
// Wait a maximum of 10s for Serial Monitor
while (!debugSerial && millis() < 10000)
;
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
// turn off the LED
digitalWrite(LED_BUILTIN, LOW);
// show the TTN status
ttn.showStatus();
// join TTN
ttn.join(appEui, appKey);
}
void loop()
{
// Prepare payload of 1 byte to indicate LED status
byte payload[1];
payload[0] = 1;
// Send it off
ttn.sendBytes(payload, sizeof(payload));
// wait 7 seconds while flashing the LED
waitAwhile();
}
wait 7 seconds while flashing the LED
void waitAwhile()
{
for (int i=0; i <= 10; i++){
digitalWrite(LED_BUILTIN, LOW);
delay(350);
digitalWrite(LED_BUILTIN, HIGH);
delay(350);
}
}
Set Up The Things Network Application
We next setup of a The Things Network Application called charlottetown-heatmap and attached a Device to it called charlottetown-things-uno, attaching the Device EUI we'd discovered earlier; with the Device in place, we were able to copy-and-paste the appEui and appKey values from the "Example Code" section of the console into the Arduino script above, and upload that to the Things Uno.
Success!
As soon as the script was uploaded, we started to see activity under the "Data" tab of the "Device" section in The Things Network console, which confirmed that everything LoRaWAN was working properly.
Making the Things Uno Portable
With the Things Uno successfully broadcasting LoRaWAN payloads, we were ready for testing in the field, but first we needed some way to make the Uno portable, replacing the USB or mains power with a battery.
First Try: USB Powerbank
Our first thought was to simply use a spare Anker powerbank, otherwise used to charge phones and tablets, to power the Uno via USB.
This worked. But then it didn't.
It turns out that the powerbank is "smart" enough that it shuts itself off after 30 seconds, and phenomenon that's discussed at some length here.
Second Try: 9V Battery
In addition to power via USB, the Things Uno also has a power port that accepts the kind of "barrel" connector you often see on the ends of power supplies for consumer electronics; fortunately we had a box of these lying around, and were able to scavenge an old one for parts.
We snipped its cord about 10 cm from the barrel, stripped the wires down to copper, and then attached a 9V battery "rigid snap connector" (purchased from the local Radio Shack). Lacking a polished way of finishing up the wiring, this was cobbled together with masking tape, and ended up looking like this:
Success!
Plugging the barrel connector into the Things Uno, it powered right up, started flashing its LED as programmed, and sending LoRaWAN payloads every 10 seconds.
A Case for the Things Uno
If were were going to be taking the Things Uno out into the field, we wanted to protect it from the elements a little; fortunately, someone else had already gone down this road, and we were able to download a ready-made STL file for our 3D printer.
It's Too Big!
Looking at a preview of the Things Uno case STL file, it became evident that we couldn't use it as-is on our Monoprice Select Mini 3D printer, as the printer only has a 10 cm by 10 cm bed, and the case parts, top and bottom, were ganged together in the STL file:
The solution to this was to import the STL file into Tinkercad and then to draw a "hole" over one side, join the "hole" to the case (thus erasing the other half) and exporting the result as a brand new STL file, and then to repeat for the other side. The result was two separate STL files, one for the bottom of the case, and one for the top:
(The original case and the sliced up versions are Creative Commons Attribution Share Alike. Commercial use is allowed, you must attribute the creator, you may remix this work and the remixed work should be made available under this license).
Printing the Case
Printing the case took a long time–about 3 hours for the top and 2.5 hours for the bottom–but the result was very satisfying and fits together well, leaving all the bits of the Things Uno that can benefit from being exposed open for access.
Range Testing
With the gateway in place and working, and a test device broadcasting LoRaWAN payloads successfully, we were ready for testing the range of the gateway.
We strapped the Things Uno and its 9V battery together with an elastic band, installed the TTN Mapper app for Android on our phone, connected the app to our charlottetown-things-uno device, set up an "experiment" in the app called charlottetown_heatmap_20160608, and went for a drive, up and down, back and forth, through the neighbourhood around City Hall, with the Uno on the dashboard.
Here's the route (with the location of City Hall, with The Things Gateway, marked):
Range Test Results
The results of the range test showed us a couple of things:
- Coverage is much better to the southeast of the gateway, which makes sense, as it's in a southeast-facing window.
- The longest distance from which a payload was received was 724 m, from the tip of Queen Street.
- The area of generally reliable coverage, was about 2 blocks in all directions, with the exception of the "back side" of the gateway, to the northwest, which had very spotty coverage.
- Beyond that area, coverage appeared to be mostly influenced by obstruction from buildings.
Here's the map from TTN Mapper, with the dots representing the location of each LoRaWAN packet received, and the "redness" of the dots indicating the received signal strength (RSSI) value:
Next Steps
Our goal is to maximize coverage of the City of Charlottetown with as few gateways as possible; the tests to date show that with the current location, at the current height, with the current limitations, with the current antenna, our coverage is very limited.
Other Locations?
We're investigating other locations for The Things Gateway. There are taller buildings in the area–a financial tower, a tall hotel–and there's also the possibility of using radio towers at the University of Prince Edward Island or elsewhere (although an outdoor location means we'd need to weatherproof the gateway, and be more concerned about lightning protection).
External Antenna?
Testing to date has used the small attached antenna included with The Things Gateway; this limits the locations where the gateway can be placed because the antenna and the gateway itself are a "package deal." If we used an external antenna, this limitation would be lifted, and we could locate the antenna and the gateway a distance apart from each other. We're currently looking for expertise in this realm.
There's also the possibility of using an external antenna with the Things Uno; this is documented here.
What else?
If you have suggestions for other steps we might take to improve coverage, please let me know.