- Overview
- Create Converter templates
- Create Integration template
- Modify Edge Root Rule chain for Downlinks
- Assign Integration to Edge
- Send uplink message
- Send downlink message
- Next steps
Overview
HTTP Integration allows converting existing protocols and payload formats to ThingsBoard Edge message format and is useful in several deployment scenarios:
- stream device and/or asset data from external system, IoT platform or connectivity provider back-end.
- stream device and/or asset data from your custom application running in the cloud.
- connect the existing device with custom HTTP based protocol to ThingsBoard Edge.
Create Converter templates
Converter and Integration templates are created on the Cloud, so please log in as Tenant administrator to cloud instance.
Uplink Converter template
Before creating the Integration template, you need to create an Uplink and Downlink converter templates in Converters templates page. Uplink is necessary in order to convert the incoming data from the device into the required format for displaying them in ThingsBoard Edge. 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.
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
// Decode an uplink message from a buffer
// payload - array of bytes
// metadata - key/value object
/** Decoder **/
// decode payload to string
// var payloadStr = decodeToString(payload);
// decode payload to JSON
var data = decodeToJson(payload);
var deviceName = data.deviceName;
// Result object with device attributes/telemetry data
var result = {
deviceName: deviceName,
deviceType: 'default',
attributes: {
model: data.model,
},
telemetry: {
temperature: data.temperature
}
};
/** 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;
}
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.
Downlink Converter template
Create Downlink in Converter templates page as well. To see events select Debug checkbox.
You can customize a downlink according to your configuration. Let’s consider an example where we send an attribute update message. An example of downlink converter:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 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
var result = {
// downlink data content type: JSON, TEXT or BINARY (base64 format)
contentType: "JSON",
// downlink data
data: JSON.stringify(msg),
// Optional metadata object presented in key/value format
metadata: {
}
};
return result;
Create Integration template
Now that the Uplink and Downlink converter templates have been created, it is possible to create an integration.
Modify Edge Root Rule chain for Downlinks
We can send a downlink message to the device from Rule chain using the rule node. To be able to send downlink over integration we need to modify ‘Edge Root Rule chain’ on the cloud. For example, create an integration downlink node and set the ‘Attributes updated’ link to it. When changes are made to device attribute, the downlink message will be sent to the integration.
Assign Integration to Edge
Once converter and integration templates are created, we can assign Integration template to Edge. Because we are using placeholder ${{edgeBaseUrl}} in the integration configuration, we need to add attribute edgeBaseUrl to edge first. You need to provide IP address and port of your Edge instance as edgeBaseUrl attribute. Once attribute added, we are ready to assign integration and verify that it’s added.
- Add edgeBaseUrl attribute to Edge and set value as your Edge IP:port
- Click Manage Integrations button of Edge entity
- Assign Integration to the Edge
- Login to your ThingsBoard PE Edge instance and open Integrations page - placeholder is going to be replaced by attribute value
Send uplink message
To send an uplink message, you need HTTP endpoint URL from the integration.
Let’s log in to ThingsBoard Edge and go to the Integrations page. Find your HTTP integration and click on it. There you can find the HTTP endpoint URL. Click on the icon to copy the url.
Use this command to send the message. Replace $DEVICE_NAME and $YOUR_HTTP_ENDPOINT_URL with corresponding values.
1
curl -v -X POST -d "{\"deviceName\":\"$DEVICE_NAME\",\"temperature\":33,\"model\":\"test\"}" $YOUR_HTTP_ENDPOINT_URL -H "Content-Type:application/json"
The created device with data can be seen in the section Device groups -> All on the Edge:
Received data can be viewed in the Uplink converter. In the ‘In’ and ‘Out’ blocks of the Events tab:
Send downlink message
Now let’s check downlink functionality. Let’s add firmware shared attribute:
To make sure that downlink message sent to integration you can check ‘Events’ tab of integration:
Now we’ll need to send again message to HTTP integration and see downlink response. Please use the same command that was used before (Replace $DEVICE_NAME and $YOUR_HTTP_ENDPOINT_URL with corresponding values):
1
curl -v -X POST -d "{\"deviceName\":\"$DEVICE_NAME\",\"temperature\":33,\"model\":\"test\"}" $YOUR_HTTP_ENDPOINT_URL -H "Content-Type:application/json"
An example of sent message and a response from ThingsBoard Edge in the terminal:
Next steps
-
Getting started guide - Provide quick overview of main ThingsBoard Edge features. Designed to be completed in 15-30 minutes:
-
Installation guides - Learn how to setup ThingsBoard Edge on various available operating systems and connect to ThingsBoard CE server.
-
Edge Rule Engine:
-
Overview - Learn about ThingsBoard Edge Rule Engine.
-
Rule Chain Templates - Learn how to use ThingsBoard Edge Rule Chain Templates.
-
Provision Rule Chains from cloud to edge - Learn how to provision edge rule chains from cloud to edge.
-
Push data from edge to cloud and vice versa - Learn how to push data from edge to cloud and vice versa.
-
- Security:
- gRPC over SSL/TLS - Learn how to configure gRPC over SSL/TLS for communication between edge and cloud.
-
Features:
-
Edge Status - Learn about Edge Status page on ThingsBoard Edge.
-
Cloud Events - Learn about Cloud Events page on ThingsBoard Edge.
-
-
Use cases:
-
Manage alarms and RPC requests on edge devices - This guide will show how to generate local alarms on the edge and send RPC requests to devices connected to edge:
-
Data filtering and traffic reduce - This guide will show how to send to cloud from edge only filterd amount of device data:
-
- Roadmap - ThingsBoard Edge roadmap.