The Gateway is a special type of device in ThingsBoard that is able to act as a bridge between external devices connected to different systems and ThingsBoard. Gateway API provides the ability to exchange data between multiple devices and the platform using single MQTT connection. The Gateway also acts as a ThingsBoard device and can leverage existing MQTT Device API to report stats, receive configuration updates and much more.
The API listed below is used by ThingsBoard open-source IoT Gateway.
Please refer to generic MQTT Device API to get information about data format, authentication options, etc.
In order to inform ThingsBoard that device is connected to the Gateway, one needs to publish following message:
Topic: v1/gateway/connect
Message: {"device":"Device A"}
where Device A is your device name.
Once received, ThingsBoard will lookup or create a device with the name specified. Also, ThingsBoard will publish messages about new attribute updates and RPC commands for a particular device to this Gateway.
In order to inform ThingsBoard that device is disconnected from the Gateway, one needs to publish following message:
Topic: v1/gateway/disconnect
Message: {"device":"Device A"}
where Device A is your device name.
Once received, ThingsBoard will no longer publish updates for this particular device to this Gateway.
ThingsBoard attributes API allows devices to
In order to publish client-side device attributes to ThingsBoard server node, send PUBLISH message to the following topic:
Topic: v1/gateway/attributes
Message: {"Device A":{"attribute1":"value1", "attribute2": 42}, "Device B":{"attribute1":"value1", "attribute2": 42}}
where Device A and Device B are your device names, attribute1 and attribute2 are attribute keys.
In order to request client-side or shared device attributes to ThingsBoard server node, send PUBLISH message to the following topic:
Topic: v1/gateway/attributes/request
Message: {"id": $request_id, "device": "Device A", "client": true, "key": "attribute1"}
where $request_id is your integer request identifier, Device A is your device name, client identifies a client or shared attribute scope and key is the attribute key.
Before sending PUBLISH message with the request, client need to subscribe to
Topic: v1/gateway/attributes/response
and expect messages with result in the following format:
Message: {"id": $request_id, "device": "Device A", "value": "value1"}
In order to subscribe to shared device attribute changes, send SUBSCRIBE message to the following topic:
v1/gateway/attributes
and expect messages with result in the following format:
Message: {"device": "Device A", "data": {"attribute1": "value1", "attribute2": 42}}
In order to publish device telemetry to ThingsBoard server node, send PUBLISH message to the following topic:
Topic: v1/gateway/telemetry
Message:
{
"Device A": [
{
"ts": 1483228800000,
"values": {
"temperature": 42,
"humidity": 80
}
},
{
"ts": 1483228801000,
"values": {
"temperature": 43,
"humidity": 82
}
}
],
"Device B": [
{
"ts": 1483228800000,
"values": {
"temperature": 42,
"humidity": 80
}
}
]
}
where Device A and Device B are your device names, temperature and humidity are telemetry keys and ts is unix timestamp in milliseconds.
In order to subscribe to RPC commands from the server, send SUBSCRIBE message to the following topic:
v1/gateway/rpc
and expect messages with individual commands in the following format:
{"device": "Device A", "data": {"id": $request_id, "method": "toggle_gpio", "params": {"pin":1}}}
Once command is processed by device, gateway can send commands back using following format:
{"device": "Device A", "id": $request_id, "data": {"success": true}}
where $request_id is your integer request identifier, Device A is your device name and method is your RPC method name.
Please see the corresponding article to get more information about the Claiming devices feature.
In order to initiate claiming device, send PUBLISH message to the following topic:
Topic: v1/gateway/claim
Message:
{
"Device A": {
"secretKey": "value_A",
"durationMs": 60000
},
"Device B": {
"secretKey": "value_B",
"durationMs": 60000
}
}
where Device A and Device B are your device names, secretKey and durationMs are optional keys. In case the secretKey is not specified, the empty string as a default value is used. In case the durationMs is not specified, the system parameter device.claim.duration is used (in the file /etc/thingsboard/conf/thingsboard.yml).
MQTT transport can be fully customized for specific use-case by changing the corresponding module.
Getting started guides - These guides provide quick overview of main ThingsBoard features. Designed to be completed in 15-30 minutes.
Installation guides - Learn how to setup ThingsBoard on various available operating systems.
Data visualization - These guides contain instructions how to configure complex ThingsBoard dashboards.
Data processing & actions - Learn how to use ThingsBoard Rule Engine.
IoT Data analytics - Learn how to use rule engine to perform basic analytics tasks.
Hardware samples - Learn how to connect various hardware platforms to ThingsBoard.
Advanced features - Learn about advanced ThingsBoard features.
Contribution and Development - Learn about contribution and development in ThingsBoard.