Over a million developers have joined DZone.

Integrating The Things Network Devices with the ThingsBoard Platform

DZone 's Guide to

Integrating The Things Network Devices with the ThingsBoard Platform

Learn how to integrate devices on The Things Network with the ThingsBoard platform.

· IoT Zone ·
Free Resource


Currently, more and more devices are connected to the global network using LPWAN technologies, like Sigfox, NB-IOT, and LoRa. While selected networks resolve connection tasks, there are plenty of other tasks that should also be resolved. It can be device provisioning and maintenance, data visualization and analytics, and building business workflows on top of the data submitted from devices. The ThingsBoard IoT platform can resolve all of those tasks. And, the most interesting part of the ThingsBoard that it is an open-source project.

What is The Things Network (TTN)?

The Things Network is a global, community-driven LPWAN provider that is based on a LoRaWAN stack. 

What is the ThingsBoard?

It is an open-source IoT platform for data collection, processing, visualization, and device management. Since the ThingsBoard Version 2.0, the new event bases workflow engine is available for all platform users.

How to Integrate

1. Register Application in the TTN
This application will be used for integrating TTN devices with the ThingsBoard. The application ID and access key will be used for integrating two platforms. In fact, integration is performed over the MQTT channel. ThingsBoard acts like an MQTT client where TTN is an MQTT broker.

Here is what the application configuration will look like:
Image title

Note: The 'Handler Registration' option will determine the region where an application will be registered. We will need this info when configuring integration in the ThingsBoard.

2. Create an Uplink Data Converter in the ThingsBoard
Next, use the data converter for transforming an incoming payload in the required message format. Here is an example of incoming payload:

  "app_id": "tb_platform",
  "dev_id": "thermostat_a",
  "hardware_serial": "*********",
  "port": 1,
  "counter": 0,
  "payload_raw": "Dw==",
  "payload_fields": {
    "temperature": 15
  "metadata": {
    "time": "2018-06-07T17:31:18.670792607Z"

There are integration specific fields in the incoming payload, like app_id   or dev_id  . Hardware _serial fields  contain device EUI from TTN platform. The actual payload from the device stored inside payload_raw  and payload_fields  properties.

For example, our device submits a 1-byte payload that contains current temperature value. And, we want to save this value as a telemetry of the device. Here is what the converter will look like:

var data = decodeToJson(payload);
var deviceName = data.dev_id;
var deviceType = data.app_id;

var result = {
  deviceName: deviceName,
  deviceType: deviceType,
  telemetry: {
  temperature: data.payload_fields.temperature

function decodeToString(payload) {
return String.fromCharCode.apply(String, payload);

function decodeToJson(payload) {
  var str = decodeToString(payload);
  var data = JSON.parse(str);
  return data;

return result;

3. Create ThingsBoard Integration
The final step is to create 'integration' on the ThingsBoard side. Open Integrations section and add new Integration with type TheThingsNetwork. Select the uplink data converter from the previous step and fill in the required fields:
Image title

4. Verify the Results

After the device sends an uplink message from TheThingsNetwork, it will be automatically registered in the ThingsBoard and the submitted data will be saved as a telemetry of the device. Here is what it will look like:

Image title

For sending Downlink messages to the device, when some events occur, the administrator can configure the required workflow in the ThingsBoard Rule engine. The integration Downlink node is used for sending such messages. More details you can be found in this ThingsBoard Rule engine tutorial.

Image title

What's Next?

Now, integration is finished. From this point, when a device sends a payload to the  tb_application , it will be transferred directly to the ThingsBoard platform. If a device was not seen before, a new device will be created.

It is also possible to send Downlink messages and process any events using the event-based workflow engine inside the ThingsBoard. 

You can find more details about those in the following links:

1. https://thingsboard.io/docs/user-guide/integrations/ttn/
2. https://thingsboard.io/docs/user-guide/rule-engine-2-0/re-getting-started/
3. https://www.thethingsnetwork.org/docs/

iot development ,iot platform ,lora ,event processing ,dashboard platform ,mqtt ,thingsboard ,ttn ,the things network

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}