Thingsboard 时序数据和属性数据

Thingboard id之谜

thingboard使用cassandra-java提供的jar包生成带“-”的uuid;

存储到pg的id是去掉"-"(转换类UUIDConverter),并按照一定规则排序的31位uuid(重点31位MLG)

返回给前端页面使用的,提供是带“-”的uuid(getData方法会转换)

 

时序数据

启用pg和cassandra混合模式后,cassandra只存储和时序数据相关的三张表

ts_kv_cf、ts_kv_latest_cf、ts_kv_partition_cf

thingsboard时序数据说明文档 https://thingsboard.io/docs/user-guide/telemetry/#websocket-api

 

主要接口

保存时序数据接口

POST  /api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}
// 还有一个接口路径上多一个{ttl}的接口
Head  X-Authorization :token
Body 样例 {"key1":"value1", "key2":true, "key3": 3.0, "key4": 4}
含时间遥测数据,毫秒值 
{"ts":1561448813161, "values":{"key1":"value1", "key2":"value2"}}
调用样例:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: */*' --header 'X-Authorization: Bearer –token--' -d '{"key1":"value1", "key2":true, "key3": 3.0, "key4": 4}' 'http://127.0.0.1:8080/api/plugins/telemetry/DEVICE/75a82e30-697f-11e9-8f29-453c4a68cf5e/timeseries/TEST'

名称

类型

含义

是否必填

entityType

String

实体类型,例如DEVICE

entityId

String

实体id

scope

String

无(随意填一个)

body

Application/json

Post消息体,遥测数据

查询时序数据接口

/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries
Head  X-Authorization :token
//调用样例
curl -X GET --header 'Accept: application/json' --header 'X-Authorization: Bearer --token' 'http://127.0.0.1:8080/api/plugins/telemetry/DEVICE/75a82e30-697f-11e9-8f29-453c4a68cf5e/values/timeseries?limit=100&agg=NONE&keys=key1%2Ckey2&startTs=1451649500512&endTs=1556435934100'

名称

类型

含义

是否必填

entityType

String

实体类型,例如DEVICE

entityId

String

实体id

keys

request param

遥测属性键名

limit

request param

返回条数

startTs

request param

开始时间毫秒值

endTs

request param

结束时间毫秒值

注意 startTs要小于查询时序数据的时间

 

cassandra sql查询样例

use compaas;
--- 查询最新遥测数据
select * from ts_kv_latest_cf where entity_type = 'DEVICE' and entity_id = 6f4c5940-672b-11e9-87c3-1b15e9582776;

--查询key分区
select * from ts_kv_partitions_cf where entity_type = 'DEVICE' and entity_id = 2523e9d0-60f7-11e9-b7b8-edae55f030fc and key = '定子温度';

use compaas;
--强制查询
---select * from ts_kv_cf where entity_type = 'DEVICE' and entity_id  = 2523e9d0-60f7-11e9-b7b8-edae55f030fc ALLOW FILTERING;
---select * from ts_kv_cf where entity_type = 'DEVICE' and entity_id  = 2523e9d0-60f7-11e9-b7b8-edae55f030fc and key = '定子温度' ALLOW FILTERING;
select * from ts_kv_cf where entity_type = 'DEVICE' and entity_id  = 2523e9d0-60f7-11e9-b7b8-edae55f030fc 
   and key = '定子温度' and partition = 1554076800000;
   
   use compaas;
   select * from ts_kv_latest_cf where entity_type = 'DEVICE' and entity_id = 75a82e30-697f-11e9-8f29-453c4a68cf5e;
   select * from ts_kv_partitions_cf where entity_type = 'DEVICE' and entity_id = 75a82e30-697f-11e9-8f29-453c4a68cf5e ALLOW FILTERING;
         
   select * from ts_kv_cf where entity_type = 'DEVICE' and entity_id  = 75a82e30-697f-11e9-8f29-453c4a68cf5e ALLOW FILTERING;
   select * from ts_kv_latest_cf where entity_type = 'DEVICE' and entity_id = 75a82e30-697f-11e9-8f29-453c4a68cf5e;

属性数据

thingsboard将属性数据分为三类:服务端属性(SERVER_SCOPE)、客户端属性(CLIENT_SCOPE)

SHARED_SCOPE(共享属性),属性存放在表attribute_kv

你可能感兴趣的:(Thingsboard)