立即试用 商务报价
专业版
文档 > 集成整合 > LORIOT

本页目录

LORIOT Integration

ThingsBoard PE功能

仅限专业版支持Platform Integrations功能。
基于ThingsBoard云服务专业版平台实例。

Overview

LORIOT is LoRaWAN network designed for connecting your devices using LoRaWAN stack. After integrating LORIOT with the ThingsBoard, you can connect, communicate, process and visualize data from devices in the ThingsBoard IoT platform.

Create LORIOT account

Choosing a package of services and server location. Then we register an account with LORIOT. For example, select the community public network server.

The LORIOT interface may change in the future.

Fill in the registration fields. The registration confirmation letter will be sent to the specified email. Follow the specified link.

Before creating the integration, you need to create an Uplink converter in Data converters. Uplink is necessary in order to convert the incoming data from the device into the required format for displaying them in ThingsBoard. Click on the “plus” and on “Create new converter”. To view the events, enable Debug. In the function decoder field, specify a script to parse and transform data.

NOTE
Although the Debug mode is very useful for development and troubleshooting, leaving it enabled in production mode may tremendously increase the disk space, used by the database, because all the debugging data is stored there. It is highly recommended to turn the Debug mode off when done debugging.

Let’s review sample uplink message from LORIOT:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
     "cmd"  : "rx",
     "EUI"  : "BE7A000000000552",
     "ts"   : 1470850675433,
     "ack"  : false,
     "fcnt" : 1,
     "port" : 1,
     "data" : "2A3F",
     "freq" : 868500000,
     "dr"   : "SF12 BW125 4/5",
     "rssi" : -130,
     "snr"  : 1.2
 }

As you can see the unique device id arrives in the “EUI” field. We will use it as a 平台中的设备名称 Device data is encoded in the “data” field. The encoded data here is:

1
"data": "2A3F"

Let’s convert them into temperature and humidity values.

2A is the value for temperature. In decoded form it will be 42

3F is the value for humidity. In decoded form it will be 63

In the converter it will be indicated like this:

1
2
temperature: stringToInt(payloadJson.data.substring(0,2)),
humidity: stringToInt(payloadJson.data.substring(2,4))

One can use either TBEL (ThingsBoard expression language) or JavaScript to develop user defined functions. We recommend utilizing TBEL as it’s execution in ThingsBoard is much more efficient compared to JS.

Example for the Uplink converter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Decode an uplink message from a buffer
// payload - array of bytes
// metadata - key/value object
/** Decoder **/
// decode payload to JSON
var payloadJson = decodeToJson(payload);
// Use EUI as unique device name.
var deviceName = payloadJson.EUI;
// Specify the device type. Use one data converter per device type or application.
var deviceType = 'temperature-sensor';
// Optionally, add the customer name and device group to automatically create them in ThingsBoard and assign new device to it.
// var customerName = 'customer';
// var groupName = 'thermostat devices';
// Result object with device/asset attributes/telemetry data
var result = {
    deviceName: deviceName,
    deviceType: deviceType,
//   customerName: customerName,
//   groupName: groupName,
    attributes: {},
    telemetry: {
        ts: payloadJson.ts,
        values: {
            temperature: parseLittleEndianHexToInt(payloadJson.data.substring(0,2)),
            humidity: parseLittleEndianHexToInt(payloadJson.data.substring(2,4)),
            fcnt: payloadJson.fcnt,
            port: payloadJson.port,
            freq: payloadJson.freq,
            dr: payloadJson.dr,
            rssi: payloadJson.rssi,
            snr: payloadJson.snr,
            rawData: payloadJson.data
        }
    }
};

return result;

You can change the decoder function while creating the converter or after creating it. If the converter has already been created, then click on the “pencil” icon to edit it. Copy the configuration example for the converter (or your own configuration) and insert it into the decoder function. Save changes by clicking on the “checkmark” icon.

Example for the Uplink converter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Decode an uplink message from a buffer
// payload - array of bytes
// metadata - key/value object
/** Decoder **/
// decode payload to JSON
var payloadJson = decodeToJson(payload);
// Use EUI as unique device name.
var deviceName = payloadJson.EUI;
// Specify the device type. Use one data converter per device type or application.
var deviceType = 'temperature-sensor';
// Optionally, add the customer name and device group to automatically create them in ThingsBoard and assign new device to it.
// var customerName = 'customer';
// var groupName = 'thermostat devices';
// Result object with device/asset attributes/telemetry data
var result = {
   deviceName: deviceName,
   deviceType: deviceType,
//   customerName: customerName,
//   groupName: groupName,
   attributes: {},
   telemetry: {
        ts: payloadJson.ts,
        values: {
            temperature: stringToInt(payloadJson.data.substring(0,2)),
            humidity: stringToInt(payloadJson.data.substring(2,4)),
            fcnt: payloadJson.fcnt,
            port: payloadJson.port,
            freq: payloadJson.freq,
            dr: payloadJson.dr,
            rssi: payloadJson.rssi,
            snr: payloadJson.snr,
            rawData: payloadJson.data
       }
   }
};
/** Helper functions **/
function decodeToString(payload) {
   return String.fromCharCode.apply(String, payload);
}
function decodeToJson(payload) {
   // covert payload to string.
   var str = decodeToString(payload);
   // parse string to JSON
   var data = JSON.parse(str);
   return data;
}
function stringToInt(hex) {
    return parseInt('0x' + hex.match(/../g).reverse().join(''));
}
return result;

You can change the decoder function while creating the converter or after creating it. If the converter has already been created, then click on the “pencil” icon to edit it. Copy the configuration example for the converter (or your own configuration) and insert it into the decoder function. Save changes by clicking on the “checkmark” icon.

Create Integration

Now that the Uplink converter has been created, it is possible to create an integration.

In order for data to be transferred from LORIOT to ThingsBoard, you need to configure an Output for your LORIOT application. You can do this manually (recommended) or ThingsBoard Integration can do this for you (you will need to specify login and password from your LORIOT account for us to be able to automatically provision the output).

Configuration the Output options

We can create Output with LORIOT or in integration by enabling the Create Loriot Application output option or specifying the “Basic” credential.

In LORIOT go to the Output menu and click on Add new output.

Then we select HTTP Push and specify the target, which is taken from the integration.

Check the Create Loriot Application output checkbox.

Let`s open the account in LORIOT. The link contains the server that we selected at the registration stage. It need to be specified in the integration.

By default, Applications is already created. It used for our integration in the example. To get the value we need, go to Аpplications.

This value needed at the stage of creating the integration to fill in the Application ID field.

Then click on the “Credentials - Basic” block and input the email and password from your account to account in LORIOT.

Enable security option

If necessary, you can specify additional parameters, without which the data will not be included in the integration. To do this, check the Enable security checkbox and click on the Headers filter. Specify an arbitrary value and save the changes.

Also need to specify this in LORIOT:

Once the Headers filter has been configured, it will also need to be specified in the uplink message as follows.

1
-H "authorization:secret"

It may be useful to “emulate” the message from device using console instead of the LORIOT server. To send an uplink message, you need a HTTP endpoint URL from the integration, port and EUI from LORIOT.

Let`s go to the Integrations tab in ThingsBoard. Find your LORIOT integration and click on it. There you can find the HTTP endpoint URL. Click on the icon to copy the url.

A port can be from 1 to 223. EUI is device EUI and is taken from the device in LORIOT.

Get EUI in LORIOT in the Devices section, where the devices have already been created:

Use this command to send message. Replace $YOUR_EUI_DEVICE and $YOUR_HTTP_ENDPOINT_URL with corresponding values.

1
curl -v -X POST -d "{\"EUI\":\"$YOUR_EUI_DEVICE\",\"deviceType\":\"temperature-sensor\",\"data\":\"2A3F\",\"port\":1,\"cmd\":\"rx\",\"dr\":\"SF12 BW125 4/5\",\"snr\":1.2,\"ack\":\"false\",\"freq\":868500000,\"fcnt\":1,\"rssi\":-130,\"ts\":1613745998000}" $YOUR_HTTP_ENDPOINT_URL -H "Content-Type:application/json"

With the enable security option: replace $YOUR_EUI_DEVICE, $YOUR_HTTP_ENDPOINT_URL and $VALUE with corresponding values.

1
curl -v -X POST -d "{\"EUI\":\"$YOUR_EUI_DEVICE\",\"deviceType\":\"temperature-sensor\",\"data\":\"2A3F\",\"port\":1,\"cmd\":\"rx\",\"dr\":\"SF12 BW125 4/5\",\"snr\":1.2,\"ack\":\"false\",\"freq\":868500000,\"fcnt\":1,\"rssi\":-130,\"ts\":1613745998000}" $YOUR_HTTP_ENDPOINT_URL -H "Content-Type:application/json" -H "$VALUE"

The created device with data can be seen in the section Device groups -> All

Received data can be viewed in the Uplink converter. In the “In” and “Out” blocks of the Events tab:

Use the Dashboards to work with data. Dashboards are a modern format for collecting and visualizing data sets. Visibility of data presentation is achieved through a variety of widgets.

ThingsBoard has examples of several types of dashboards that you can use. You can find them in Solution templates tab.

How to work with dashboards read here

Create Downlink in Data converters. To see events - enable Debug.

One can use either TBEL (ThingsBoard expression language) or JavaScript to develop user defined functions. We recommend utilizing TBEL as it’s execution in ThingsBoard is much more efficient compared to JS.

You can customize the downlink according to your configuration. Let’s consider an example where we send an attribute update message. So we should change code in the downlink encoder function under line //downlink data input

1
data: msg.firmware

Also, indicate the required parameters in the metadata:

1
2
3
4
metadata: {
  "EUI": "$Device_EUI",
  "port": 1
}

Example for downlink converter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Encode downlink data from incoming Rule Engine message
// msg - JSON message payload downlink message json
// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.
// metadata - list of key-value pairs with additional data about the message
// integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter
// Result object with encoded downlink payload
var result = {
    // downlink data content type: JSON, TEXT or BINARY (base64 format)
    contentType: "TEXT",
    // downlink data
    data: msg.firmware,
    // Optional metadata object presented in key/value format
    metadata: {
            "EUI": "BE7A000000000552",
            "port": 1
    }
};
return result;

where EUI is device EUI and is taken from the device in LORIOT. A port can be from 1 to 223

You can customize the downlink according to your configuration. Let’s consider an example where we send an attribute update message. So we should change code in the downlink encoder function under line //downlink data input

1
data: msg.firmware

Also, indicate the required parameters in the metadata:

1
2
3
4
metadata: {
  "EUI": "$Device_EUI",
  "port": 1
}

Example for downlink converter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Encode downlink data from incoming Rule Engine message
// msg - JSON message payload downlink message json
// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.
// metadata - list of key-value pairs with additional data about the message
// integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter
// Result object with encoded downlink payload
var result = {
    // downlink data content type: JSON, TEXT or BINARY (base64 format)
    contentType: "TEXT",
    // downlink data
    data: msg.firmware,
    // Optional metadata object presented in key/value format
    metadata: {
            "EUI": "BE7A000000000552",
            "port": 1
    }
};
return result;

where EUI is device EUI and is taken from the device in LORIOT. A port can be from 1 to 223

Get EUI in LORIOT in the Devices section, where the devices have already been created:

Add a converter to the integration. You can do this at the stage of creating an integration or editing it.

To send Downlink, enable the Send downlink option in the integration. Once we enable the “Send downlink” option, specify the Server, Application ID, Application Access Token in the fields:

To get this data - go to your account in LORIOT.

Data to fill in the Server field:

Data to fill in the Application ID field:

After that, go to Application and go to the Access Tokens section. Find the token that will be specified in the integration.

We can send a message to the device from Rule chain using the rule node. For our example, we create the integration downlink node and set the “Attributes updated” link to it. When changes are made to the attribute, the downlink message will be sent to the integration.

We go to the Device group section in the All folder, to see this with an example. We have indicated the firmware of the device in the Shared attributes. Now we edit it by clicking on the “pencil” icon. Then we make changes to the attribute (change the firmware from 01052020.v1.1 to 01052020.v1.2) and save the data.

Received data and data that was sent can be viewed in the downlink converter.In the “In” block of the Events tab, we see what data entered:

The “Out” field displays messages to device:

It is possible to check that messages have reached LORIOT on the Devices -> LoRaWAN Parameters page at the very bottom in the Downlink Queue field.

Next steps

  • 入门指南 - 快速学习ThingsBoard相关功能。

  • 安装指南 - 学习如何在各种操作系统上安装ThingsBoard。

  • 可 视 化 - 学习如何配置复杂的ThingsBoard仪表板说明。

  • 数据处理 - 学习如何使用ThingsBoard规则引擎。

  • 数据分析 - 学习如何使用规则引擎执行基本的分析任务。

  • 硬件样品 - 学习如何将各种硬件平台连接到ThingsBoard。

  • 高级功能 - 学习高级ThingsBoard功能。