---
agentTools:
  projectIndex: https://docs.iotcreators.com/v2.1/llms.txt
---

# ThingsBoard

In this chapter we describe how to integrate IoT Creators SCS  with Thingsboard

We show how you can implement your own end-to-end IoT solution for sensor data monitoring.

Beside the NB-IoT sensor which sends data via UDP or CoAP/Leul to IoT Creators Data Provisioning service you need to have access to [ThingsBoard Cloud](https://thingsboard.cloud).

####

####

\###Architecture

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/19f90de-Thingsboard_Grafik2.png",
        "Thingsboard Grafik2.png",
        1755,
        788,
        "#d0c9d1"
      ]
    }
  ]
}
[/block]

As you can see in the architecture the data from your sensor will be forwarded to ThingsBoard via HTTP. The integration in ThingsBoard is linked to a data converter which decodes the payload. The converted data can then be used to monitore your sensor in ThingsBoard.

####

[block:callout]
{
  "type": "info",
  "title": "Need help?",
  "body": "In case you have any problems with the integration you can find help in the [forum](https://forum.iotcreators.com/) or write us an email: hello@iotcreators.com"
}
[/block]

####

### Perequisites

To start with this tutorial you need to fulfill the following prerequisites:

* IoT Creators account and at least a Starterkit SIM card.
* NB-IoT IoT Sensor which sends its payload via UDP to IoT Creator's UDP server (e.g. comfortsensor from IMBUILDING (see [device catalog ](https://iotcreators.com/en/catalog/) or [documentation library](https://docs.iotcreators.com/docs/imbuildings-comfort-sensor)). Any other NB-IoT devkit such as [Quectel BC66](https://docs.iotcreators.com/docs/_-quectel-bc66-t-be-dvk) will work as well.
* an account with the ThingsBoard Professional Edition (<https://thingsBoard.io/products/thingsboard-pe/>)

####

####

### Steps

Based on this prerequisites you will implement the architecture above with the following steps:

* [Step 1: Basic integration of IoT Creators and ThingsBoard](https://docs.iotcreators.com/docs/thingsboard-new#step-2-implement-the-data-converter-for-sdi-sensors)
  a) Create a converter in ThingsBoard
  b) Create an integration in ThingsBoard
  c) Configure application URL in IoT Creators Portal
  d) Check if everything worked
* [Step 2: Implement the data converter for SDI sensors](https://docs.iotcreators.com/docs/thingsboard-new#step-3-register-and-activate-your-sensor)
* Step 3: [Register and activate your sensor](https://docs.iotcreators.com/docs/thingsboard-new#step-3-register-and-activate-your-sensor)
  a) Register the device in IoT Creators Portal
  b) Create your device in ThingsBoard
  c) Activate IMBUILDING Comfort Sensor
  d) Check if everything worked

####

####

[block:api-header]
{
  "title": "Step 1: Basic integration of IoT Creators and ThingsBoard"
}
[/block]

Let's start with a simple integration. Initially, this only serves to familiarize ThingsBoard and IoT Creators Portal with each other and to create a connection between these two plattforms.

####

####

\###a) Create a converter in ThingsBoard
An integration module in ThingsBoard uses converters (or data harmonization) to make uplinks consumable by ThingsBoard and convenient for third party platforms downlinks. To understand the architecture of the integration feature in ThingsBoard you may read the corresponding documentation.
So the first part is to create a data converter, which is absolutely necessary for the integration. To do this, go to **Data converters** in the left bar and hit the '+' in the upper left corner.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/9e2fd6d-NewConverter.png",
        "NewConverter.png",
        2000,
        977,
        "#d0e0df"
      ]
    }
  ]
}
[/block]

Now you have two opportunities. In our case we select **Create new converter**.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/4aaf41f-NewConverter2.png",
        "NewConverter2.png",
        576,
        265,
        "#c1d9d6"
      ]
    }
  ]
}
[/block]

Afterwards you can see a Pop-up with a default decoder. You just have to:

* Enter the **Name** of your converter
* tick the box **Debug mode**
* click **Add**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/d1b6809-IoTConverter.png",
        "IoTConverter.png",
        2000,
        977,
        "#98a5a4"
      ]
    }
  ]
}
[/block]

####

####

\###b) Create an integration in ThingsBoard
After you successfully created your data converter you are able to create the integration in ThingsBoard. Just go to **Integrations** in the left bar and click on the grey '+' in the upper right corner like you did with the converter.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/67d59c9-NewIntegration.png",
        "NewIntegration.png",
        2000,
        977,
        "#cfdfde"
      ]
    }
  ]
}
[/block]

Now we can configure our Integration in the Pop-up. For this you have to...

* Enter the **Name**
* Enable **Debug mode**
* Select **HTTP** as the Type
* Select the **Data converter** which you created in the last step
* Enable **Replace response status from 'No-Content' to 'OK'**
* Select **Enable security**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/31f92ee-snippet.png",
        "snippet.png",
        1920,
        937,
        "#9eadab"
      ]
    }
  ]
}
[/block]

\###Add header for the security
For security reasons, we recommend to add an **Authorization** header with a generated value.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/10cd2cb-NewIntegration3.png",
        "NewIntegration3.png",
        776,
        272,
        "#f9faf9"
      ]
    }
  ]
}
[/block]

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/fc6b62c-NewIntegration4.png",
        "NewIntegration4.png",
        1063,
        270,
        "#fafbfa"
      ]
    }
  ]
}
[/block]

Afterwards you can save the integration with the **Add** button of the Pop-up.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/0ef3b02-NewIntegration5.png",
        "NewIntegration5.png",
        2000,
        977,
        "#9dacab"
      ]
    }
  ]
}
[/block]

Your ThingsBoard integration should now be available so that we can continue with connecting this integration to IoT Creators Portal.

####

####

\###c) Configure application URL in IoT Creators Portal
In this part we will take the endpoint URL and configure it in IoT Creators Portal with our security header.
To get the URL you can click on your integration and copy it by just clicking on the symbol.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/694a962-NewIntegration7.png",
        "NewIntegration7.png",
        2000,
        977,
        "#bfd5d3"
      ]
    }
  ]
}
[/block]

Now you can close the window and go to your project in IoT Creator Portal. Then switch to **YOUR APPLICATION SERVER**.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/3ea3ace-Connect.png",
        "Connect.png",
        1089,
        1125,
        "#f8f3f5"
      ]
    }
  ]
}
[/block]

Paste your copied URL from ThingsBoard in the Callback URL line.
and create the same header as you did in ThingsBoard.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/8a69bfd-Connect3.png",
        "Connect3.png",
        847,
        433,
        "#f7f4f7"
      ]
    }
  ]
}
[/block]

After that you can click on **SAVE** and should see a confirmation in the upper right corner.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/0dc9b48-Connect4.png",
        "Connect4.png",
        2000,
        977,
        "#f8f4f6"
      ]
    }
  ]
}
[/block]

####

####

### d) Check if everything worked

Let us finish this step with a simple way to doublecheck wether the connection was successful.
Like I mentioned you should have already seen a confirmation in IoT Creators Portal. Which should have look like this:

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/4ea5b7d-2021-06-17_08_20_31-Window.png",
        "2021-06-17 08_20_31-Window.png",
        325,
        73,
        "#f4f8f6"
      ]
    }
  ]
}
[/block]

When you saw an error like in the picture below I would first check if your Authorization header is correct. If so, further investigations are required.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/70cf4ae-2021-06-17_08_16_05-Window.png",
        "2021-06-17 08_16_05-Window.png",
        363,
        53,
        "#f9f2f2"
      ]
    }
  ]
}
[/block]

Even with a green notification I recommend to go back to ThingsBoard and check wether there is a new event.
To proof this you have to:

* Click on your integration in ThingsBoard
* Go to **Events**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/6c5b7a3-checkevent.png",
        "checkevent.png",
        2000,
        977,
        "#bfd6d3"
      ]
    }
  ]
}
[/block]

Here you should see a new event. If you did not get one, you will unfortunately have to check again whether the data converter and the integration are configurated correctly.

####

####

[block:api-header]
{
  "title": "Step 2: Implement the data converter for SDI sensors"
}
[/block]

Now that you get a connection between ThingsBoard and IoT Creators Portal we can focus on the SDI sensor. Let us start with the data converter. This step is necessary so that ThingsBoard can decode the data from the sensor.
For this we need to change the default decoder to our own. However, you do not have to write any code yourself to do this. You can copy ours straight away. What this decoder basically does is taking the raw data from your device, dividing it into battery voltage, temperature, humidity, co2, status and presence and returning the data as telemetry.

[block:code]
{
  "codes": [
    {
      "code": "function sdi_decode(hexString) {\n\tvar d = {};\n\td.sensorData = hexString;\n\t\n\tvar hexData = hexString.match(/..?/g);\n\t\n\tvar typeVersion = hexData[0] + hexData[1];\n\n\tif (typeVersion == '0101') { \n\t\td.status = parseInt(hexData[8], 16); \n\t\td.batteryV = parseInt(hexData[9] + hexData[10], 16) / 100; \n\t\td.temperature = parseInt(hexData[12] + hexData[13], 16) / 100; \n\t\td.humidity = parseInt(hexData[14] + hexData[15], 16) / 100; \n\t\td.co2 = parseInt(hexData[16] + hexData[17], 16); \n\t\td.presence = parseInt(hexData[18], 16); \n\t\t\n\t} else if (typeVersion == '0204') { \n\t\td.status = parseInt(hexData[8], 16); \n\t\td.batteryV = parseInt(hexData[9] + hexData[10], 16) / 100; \n\t\td.counterA = parseInt(hexData[19] + hexData[20], 16);\n\t\td.counterB = parseInt(hexData[21] + hexData[22], 16);\n\t}\n\treturn d;\n}\n\nfunction iotCr_decode(deviceType, payload) {\n  var plD = JSON.parse(payload);\n\n  if (! plD.reports || plD.reports.length == 0) {\n      return null;\n  }\n  \n  ret = [];\n  \n  len = plD.reports.length;\n  \n  for (i = 0; i < len; i++) {\n    var value = plD[\"reports\"][i][\"value\"];\n\n    if (deviceType == \"SDI\") { \n      var telemetryD = sdi_decode(value);\n      groupName = \"IMBUILDING\";\n    } \n  \n    var serialNumber = plD[\"reports\"][i][\"serialNumber\"];\n  \n    var deviceName = serialNumber;\n    deviceType = \"default\";\n    var customerName = 'customer';\n \n    d = {\n      deviceName: serialNumber,\n      deviceType: deviceType,\n      customerName: customerName,\n      groupName: groupName,\n      attributes: {\n         data: value\n      },\n      telemetry: telemetryD\n   };  \n   \n   ret[i] = d;\n  } \n  \n  return ret;\n}\n\nfunction iotCr_decode_bak(deviceType, payload) {\n  var plD = JSON.parse(payload);\n\n  if (! plD.reports || plD.reports.length == 0) {\n      return null;\n  }\n  \n  \n  var value = plD[\"reports\"][0][\"value\"];\n\n  if (deviceType == \"SDI\") { \n    var telemetryD = sdi_decode(value);\n    groupName = \"IMBUILDING\";\n  } \n  \n  var serialNumber = plD[\"reports\"][0][\"serialNumber\"];\n  \n  var deviceName = serialNumber;\n  deviceType = \"default\";\n  var customerName = 'customer';\n \n  return {\n    deviceName: serialNumber,\n    deviceType: deviceType,\n    customerName: customerName,\n    groupName: groupName,\n \n    attributes: {\n         data: value\n    },\n\n    telemetry: telemetryD\n };  \n}\n\nfunction decodeToString(payload) {\n   return String.fromCharCode.apply(String, payload);\n}\n\nvar payloadStr = decodeToString(payload);\nres = iotCr_decode(metadata[\"Header:devicetype\"], payloadStr);\n\nreturn res;",
      "language": "text",
      "name": "SDI decoder for ThingsBoard"
    }
  ]
}
[/block]

When you copied the code you can go back to ThingsBoard and edit your converter.
To do this you need to:

* Go to **Data Converters** in the left bar
* Click on your data converter
* Click on the pen in the upper right corner

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/b3751a5-edit_converter.png",
        "edit converter.png",
        2000,
        977,
        "#bad2d0"
      ]
    }
  ]
}
[/block]

Now you are able to replace the default decoder with the copied one (e.g. STRG+A, STRG+V) and click the checkmark in the upper right corner.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/4ee9840-edit_converter2.png",
        "edit converter2.png",
        2000,
        977,
        "#b3cfd1"
      ]
    }
  ]
}
[/block]

Now your data converter should be able to decode your sensor payload.

####

####

[block:api-header]
{
  "title": "Step 3: Register and activate your sensor"
}
[/block]

[block:callout]
{
  "type": "danger",
  "body": "It is important that you first register your device in a project of IoT Creates and than you take the device into operation. \nIf the device sends messages to IoT Creators before your registered it will be put on the blacklist. After this you can not register it without support from IoT Creators support.\nIn case this happened to your send an email to support@iotcreators.com.",
  "title": "First register than activate !"
}
[/block]

####

####

### a) Register the device in IoT Creators Portal

To register your device perform the following steps:

* Login into IoT Creators portal <https://portal.iotcreators.com/auth/login>
* Select **PROJECTS** on the left side and click **Details** button of the project for which you want to register your device.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/25f673c-starterkit.png",
        "starterkit.png",
        762,
        596,
        "#f7f1f6"
      ]
    }
  ]
}
[/block]

* Click the button **REGISTER DEVICE**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/4d25380-2021-06-10_10_04_50-Window.png",
        "2021-06-10 10_04_50-Window.png",
        907,
        443,
        "#f8f3f6"
      ]
    }
  ]
}
[/block]

* IMEI: Input the IMEI of your device
* Click button **REGISTER DEVICE**

####

####

\###b) Create your device in ThingsBoard
In this part we will create a new device which will reflect your 'real' device in ThingsBoard.
I recommend creating a new Device Group first. This helps you to have a better overview of your devices, in case there are several.

####

#### Create a new device group

* Go to Device groups in the left bar
* Click the **plus icon** in the upper right corner once again

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/f2649be-NewDevice_Group.png",
        "NewDevice Group.png",
        2000,
        915,
        "#d0e0df"
      ]
    }
  ]
}
[/block]

After that you can see a pop up window in which you have to...

* Enter the **Name** of the sensor group
* Click **Add** to save your new group

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/db9525c-NewDevice_Group2.png",
        "NewDevice Group2.png",
        1920,
        881,
        "#94a3a1"
      ]
    }
  ]
}
[/block]

Now you can create your device in this device group

#### Create a new device

* Select your device group in the left bar
* Click the *plus icon* in the upper right corner

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/4ce61c2-NewDevice.png",
        "NewDevice.png",
        2000,
        867,
        "#c4d9d7"
      ]
    }
  ]
}
[/block]

After that you see a popup window similar to the one of the device group. Now you can...

* enter the IMEI of your device as the **Name**
* click **Add** to save your new device

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/720ae93-NewDevice2.png",
        "NewDevice2.png",
        1920,
        828,
        "#a4b8b6"
      ]
    }
  ]
}
[/block]

####

####

\###c) Activate IMBUILDING Comfort Sensor
If you received an IMBUILDING comfort sensor which is already **Ready for IoT Creators** you just need to open the device on the bagside and input the 3.6V batteries. As soon you put it under power the devices attaches to the mobile network and starts to send data.

####

####

\###d) Check if everything worked
After activating the sensor you should be able to see the data from your sensor in ThingsBoard.
To check this you can do the following steps:

* 1 Go to your **Device groups** and select **IMBUILDING**
* 2 Click on your device
* 3 Check your decoded data in **Latest telemetry**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/7c0f88a-Check.png",
        "Check.png",
        2000,
        977,
        "#c1d6d5"
      ]
    }
  ]
}
[/block]

Congratulations if it looks like that, everything worked and now you are able to do cool stuff with the data like creating a dashboard with a thermometer or a diagram of the co2.

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/13b4131-Check2.png",
        "Check2.png",
        1920,
        937,
        "#bdbdc7"
      ]
    }
  ]
}
[/block]

If you want to learn how to do that, I recommend the [documentation ](https://thingsboard.io/docs/pe/user-guide/dashboards) from ThingsBoard.