This guide will help you to get familiar with REST Connector configuration for ThingsBoard IoT Gateway.
Use general configuration guide to enable this Connector.
The purpose of this Connector is to create API endpoints and get data from received requests.
Connector is also able to push data to external HTTP(S) API based on the updates/commands from ThingsBoard.
This connector is useful when you have some HTTP(S) API endpoints in your device or some data in external resource and you would like to push this data to the ThingsBoard.
We will describe connector configuration file below.
Connector configuration is a JSON file that contains information about how to create API endpoints and how to process the data.
Let’s review the format of the configuration file using example below.
Parameter | Default value | Description |
---|---|---|
host | http://127.0.0.1:5000 | Domain address or ip of the server. |
SSLVerify | true | Verify or no SSL certificate on the server if available. |
This configuration section contains array of objects with endpoints that the gateway will create.
Also this section contains settings about processing incoming messages (converter).
After request receiving, the message from the request is analyzed to extract device name, type and data (attributes and/or timeseries values).
By default, the gateway uses Json converter, but it is possible to provide custom converter.
Note: You can specify multiple mapping objects inside the array.
Parameter | Default value | Description |
---|---|---|
endpoint | /test_device | Url address of the endpoint. |
HTTPMethod | GET | HTTP method allowed for endpoint (GET, POST etc.). |
This section provides configuration for client authorization at the gateway for every endpoint.
One type of security configuration is Basic authentication. The REST Connector waits for HTTP requests with the Authorization header that contains the word Basic word followed by a space and a base64-encoded string username:password.
Security section in configuration file will look like this:
|
Anonymous auth is the most simple option. It is useful for testing.
Security subsection in configuration file will look like this:
|
This subsection contains configuration for processing incoming messages.
Types of request converters:
Json converter is default converter, it looks for deviceName, deviceType, attributes and telemetry in the incoming request from the client, with rules, described in this subsection:
Mapping subsection looks like:
|
A custom converter is converter written for some device:
Notate: Everything, you placed in the “converter” section will be passed to the custom converter as a configuration. Mapping subsection in the configuration looks like:
|
Configuration in this section are optional.
ThingsBoard allows to provision device attributes and fetch some of them from the device application.
You can treat this as a remote configuration for devices. Your devices are able to request shared attributes from ThingsBoard.
See user guide for more details.
The “attributeRequests” configuration allows configuring the format of the corresponding attribute request and response messages.
Parameter | Default value | Description |
---|---|---|
httpMethod | POST | HTTP method for request (GET, POST etc.). |
SSLVerify | false | Verify or no SSL certificate on the server if available. |
httpHeaders | { “CONTENT-TYPE”: “application/json” } | Object contains additional HTTP headers for request. |
security | Security for request: | |
type | basic | Security type for request to the server (basic or anonymous). |
username | user | Username for basic type of the security. |
password | passwd | Password for basic type of the security. |
timeout | 0.5 | Timeout for request. |
tries | 3 | Count of tries to send data |
allowRedirects | true | Allow request redirection. |
deviceNameFilter | .*REST$ | Regular expression device name filter, uses to determine, which function to execute. |
attributeFilter | data | Regular expression attribute name filter, uses to determine, which function to execute. |
requestUrlExpression | sensor/${deviceName}/${attributeKey} | JSON-path expression uses for creating url address to send a message. |
valueExpression | {\”${attributeKey}\”:\”${attributeValue}\”} | JSON-path expression uses for creating the message data that will send to url. |
The attributeUpdates section will look like:
"attributeUpdates": [
{
"HTTPMethod": "POST",
"SSLVerify": false,
"httpHeaders": {
"CONTENT-TYPE": "application/json"
},
"security": {
"type": "basic",
"username": "user",
"password": "passwd"
},
"timeout": 0.5,
"tries": 3,
"allowRedirects": true,
"deviceNameFilter": ".*REST$",
"attributeFilter": "data",
"requestUrlExpression": "sensor/${deviceName}/${attributeKey}",
"valueExpression": "{\"${attributeKey}\":\"${attributeValue}\"}"
}
],
ThingsBoard allows sending RPC commands to the device that is connected to ThingsBoard directly or via Gateway.
Configuration, provided in this section uses for sending RPC requests from ThingsBoard to device.
Parameter | Default value | Description |
---|---|---|
deviceNameFilter | .* | Regular expression device name filter, uses to determine, which function to execute. |
methodFilter | echo | Regular expression method name filter, uses to determine, which function to execute. |
requestUrlExpression | http://127.0.0.1:5001/${deviceName} | JSON-path expression, uses to create url address to send RPC request. |
responseTimeout | 1 | Timeout for request. |
httpMethod | GET | HTTP method for request (GET, POST etc.). |
valueExpression | ${params} | JSON-path expression, uses for creating data for sending. |
timeout | 0.5 | Timeout for request. |
tries | 3 | Count of tries to send data |
httpHeaders | { “CONTENT-TYPE”: “application/json” } | Object contains additional HTTP headers for request. |
security | Security for request: | |
type | anonymous | Security type for request to the server (basic or anonymous). |
"serverSideRpc": [
{
"deviceNameFilter": ".*",
"methodFilter": "echo",
"requestUrlExpression": "http://127.0.0.1:5001/${deviceName}",
"responseTimeout": 1,
"HTTPMethod": "GET",
"valueExpression": "${params}",
"timeout": 0.5,
"tries": 3,
"httpHeaders": {
"Content-Type": "application/json"
},
"security": {
"type": "anonymous"
}
},
{
"deviceNameFilter": ".*",
"methodFilter": "no-reply",
"requestUrlExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"HTTPMethod": "POST",
"valueExpression": "${params}",
"httpHeaders": {
"Content-Type": "application/json"
}
}
]
Explore guides related to main ThingsBoard features: