ThingsBoradAPI(MQTT设备API)

MQTT直连接口

设备使用mqtt发送遥测数据,从官网api查看发送路径
MQTT Device API Reference

连接协议API具体作用请求路径
MQTT遥测API上传设备遥测v1/devices/me/telemetry
属性API上传设备属性v1/devices/me/attributes
从服务器请求属性值(客户端和共享设备属性)v1/devices/me/attributes/request/$request_id
从服务器订阅属性更新v1/devices/me/attributes
服务端RPC1 从服务器订阅RPC命令v1/devices/me/rpc/request/+
2 订阅后,客户端将接收单独的命令,将其作为发布消息发送到相应的主题:其中$request_id是整数请求标识符。v1/devices/me/rpc/request/$request_id
3 客户端应发布对以下主题的响应v1/devices/me/rpc/response/$request_id
客户端RPC1 发送RPC命令到服务器,其中,$REQUEST_ID是整数请求标识符v1/devices/me/rpc/request/$request_id
2 来自服务器的响应将发布到以下主题v1/devices/me/rpc/response/$request_id
认领设备发起申请设备v1/devices/me/claim

Telemetry upload API 遥测上传 API

In order to publish telemetry data to ThingsBoard server node, send PUBLISH message to the following topic:
要将遥测数据发布到 ThingsBoard 服务器节点,请向以下主题发送 PUBLISH 消息:

v1/devices/me/telemetry

The simplest supported data formats are:
支持的最简单的数据格式为:

{"key1":"value1", "key2":"value2"}

or

[{"key1":"value1"}, {"key2":"value2"}]

Attributes API

ThingsBoard attributes API allows devices to
ThingsBoard 属性 API 允许设备

  • Upload client-side device attributes to the server.
    将客户端设备属性上传到服务器。
  • Request client-side and shared device attributes from the server.
    从服务器请求客户端和共享设备属性。
  • Subscribe to shared device attributes from the server.
    从服务器订阅共享设备属性。
Publish attribute update to the server

将客户端属性更新发布到服务器(设备特有的)
In order to publish client-side device attributes to ThingsBoard server node, send PUBLISH message to the following topic:
要将客户端设备属性发布到 ThingsBoard 服务器节点,请向以下主题发送 PUBLISH 消息:

v1/devices/me/attributes

例如

{"hardWareVersion":"0.1", "softWareVersion":"1.2"}

上面默认是发到客户端设备属性里的,
1 如果要发到服务端/公共属性,可以修改规则链节点Post attributes之后指向的节点类型,例如改成save attributes(选择服务端节点)image.png

image.png
2 如果post attributes要传到遥测timeseries,会报错
java.lang.IllegalArgumentException: Unsupported msg type: POST_ATTRIBUTES_REQUEST(不支持节点类型)
解决办法:既然遥测timeseries不支持post attributes,那把postattributes传的节点数据类型改变成,把数据类型转化成遥测节点类型POST_TELEMETRY_REQUEST(return {msg: msg, metadata: metadata, msgType: “POST_TELEMETRY_REQUEST”};)
image.png

Request attribute values from the server

从服务器请求属性值
image.png
In order to request client-side or shared device attributes to ThingsBoard server node, send PUBLISH message to the following topic:
要向 ThingsBoard 服务器节点请求客户端或共享设备属性,请向以下主题发送 PUBLISH 消息:

v1/devices/me/attributes/request/$request_id

where r e q u e s t i d ∗ ∗ i s y o u r i n t e g e r r e q u e s t i d e n t i f i e r . B e f o r e s e n d i n g P U B L I S H m e s s a g e w i t h t h e r e q u e s t , c l i e n t n e e d t o s u b s c r i b e t o 其中 ∗ ∗ request_id** is your integer request identifier. Before sending PUBLISH message with the request, client need to subscribe to 其中 ** requestidisyourintegerrequestidentifier.BeforesendingPUBLISHmessagewiththerequest,clientneedtosubscribeto其中request_id 是整数请求标识符。在发送带有请求的 PUBLISH 消息之前,客户端需要订阅

v1/devices/me/attributes/response/+

发送数据示例

示例
订阅v1/devices/me/attributes/response/+
请求v1/devices/me/attributes/request/1
{"clientKeys":"hardWareVersion,softWareVersion", "sharedKeys":"hello"}

image.png

Subscribe to attribute updates from the server

从服务器订阅属性更新
In order to subscribe to shared device attribute changes, send SUBSCRIBE message to the following topic:
要订阅共享设备属性更改,请向以下主题发送 SUBSCRIBE 消息:
image.png

v1/devices/me/attributes

发一条数据测试
image.png
当其中一个服务器端组件(如 REST API 或规则链)更改共享属性时,客户端将收到更新:
image.png

RPC API

Server-side RPC

In order to subscribe to RPC commands from the server, send SUBSCRIBE message to the following topic:
要从服务器订阅 RPC 命令,请向以下主题发送 SUBSCRIBE 消息:

v1/devices/me/rpc/request/+

Once subscribed, the client will receive individual commands as a PUBLISH message to the corresponding topic:
订阅后,客户端将接收单个命令作为相应主题的 PUBLISH 消息:

v1/devices/me/rpc/request/$request_id

where r e q u e s t i d ∗ ∗ i s a n i n t e g e r r e q u e s t i d e n t i f i e r . 其中 ∗ ∗ request_id** is an integer request identifier. 其中 ** requestidisanintegerrequestidentifier.其中request_id 是整数请求标识符。
The client should publish the response to the following topic:
客户端应发布对以下主题的响应:

v1/devices/me/rpc/response/$request_id

dashboard创建小部件rpc debug terminal
image.png
实际发送了请求为(twoway表示是一个双向的rpc,后缀是设备的id)image.png
发送的数据(与terminal发的数据不同,实际转成了json发送)
image.png
通过mqttx手动回复请求
image.png

认领设备

为了发起申请设备,向以下主题发送PUBLISH消息:

v1/devices/me/claim

The supported data format is:
支持的数据格式为:

{"secretKey":"value", "durationMs":60000}

请注意,上述字段是可选的。如果未指定secretKey,则使用空字符串作为默认值。如果没有指定durationMs,则使用系统参数device.claim.duration(在文件/etc/thingsboard/conf/thingsboard.yml中)。

  • 24
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值