Standard service - a fixed amount of work that is performed at a fixed price.  Post Service


Tuesday, 09 July 2019 10:10

The Things Network

Written by
Rate this item
(0 votes)

If you have listened to the last episode of Labs Talk, you’ll roughly know what The Things Network is all about. It’s a global community of IoT enthusiasts – it’s all

about connecting “your thing” to “your application”. The Things Network uses LoRaWAN, which simply means that you can deploy low-power devices that send infrequent data payloads to gateways that can be up to many kilometers away. From the gateways, the on-device encrypted payloads are forwarded to network servers, where the messages are de-duplicated (gateways are pretty dumb, they pretty much just forward the payloads), decoded and beautified (transformed) before they can be sent on to your application.

Exploring The Things Network was a long-time wish of mine and finally the Labs Talk episode with Wienke Giezeman gave me enough reasons to just do it. Thx Wienke for getting us off the ground!

This blog post is a small intro to The Things Network (TTN) and how I integrated TTN in the most simplest way to Kyma, the open-source extension framework for enterprise applications.

Let’s first take a look how LoraWAN Networks work in general:

The typically low-power devices are “out in the field” and use LoRaWAN to send data via their LoRa (Long Range) radios. Here in Europe the free and open-to-all 868MHz frequency band is used. Multiple gateways might receive these payloads and based on their configuration they will then forward the data to a configured network server. The network servers will typically deduplicate the messages, decode and transform the byte-based payloads and depending on the features available, also forward the messages to the user’s apps. How these messages are forwarded depends on the integrations available, e.g. it could be as simple as a HTTP Post or a MQTT-based integration.

The setup I’ve created is quite simple, take a look:

The device I am using is The Things Node, a developer-friendly LoRa device which is powered by an Arduino IDE compatible SparkFun Pro Mini board. For the gateway, I am super grateful that Wienke was able to send me an indoor gateway (preconfigured for TTN). It was literally setup in a few minutes and even though it is called “indoor” the range is quite amazing. The gateway is plugged into a power outlet on the ground floor and even on the 4th floor with tons of concrete and metal around us I was able to get messages through. It’s indoor, but “long range indoor” :-) The network servers I am using for this exploration are by The Things Network, community-provided and fair-use. In the web-based console of The Things Network, you can register devices and gateways. Once you’ve created an app (has multiple devices), you can also add various integrations. Here, I chose the HTTP integration which sends on the decoded and transformed message payload in JSON-format to my HTTP endpoint of choice. As we’ve recently just setup a new Kyma cluster, it was super easy to create a new Lambda function in Kyma and wire the TTN HTTP integration to the newly exposed function.

The Things Network console has a pretty useful data logging page, which shows messages as they are received by the network.

The image above shows the messages after decoding them. For decoding the byte-based payloads, I had to register a decoding function:

function Decoder(bytes, port) { var decoded = {}; var events = { 1: 'setup', 2: 'interval', 3: 'motion', 4: 'button' }; decoded.event = events[port]; decoded.battery = (bytes[0] << 8) + bytes[1]; decoded.light = (bytes[2] << 8) + bytes[3]; decoded.temperature = ((bytes[4] << 8) + bytes[5]) / 100; return decoded; }

Let’s now take a quick look a the Kyma lambda function, which get’s called by the TTN HTTP integration – it’s really super simple:

The data received is already converted to JSON via The Things Network servers, so all that’s needed to be done is to parse the JSON and log it. There are also ways to pass Authorization tokens from the TTN integration to your servers, so this can be made more secure:

It’s really super simple to connect sensor nodes via The Things Network to your enterprise applications via the Kyma extension framework. In this blog post, I integrated TTN via the the built-in HTTP integration to a Lambda function, but other integrations might use a custom Kyma application connector and the MQTT broker which is part of the The Things Network server.

There are also more holistic approaches to connect LoraWAN Networks to SAP Leonardo IoT as Domnic has shown in this SAP Community blog post. For me, it was really important to try out the LoRaWAN connectivity for IoT and I am very pleased with the speed of setting up a basic end-to-end scenario. Feel free to get in touch via Twitter or just leave comments below.

Read 92 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.