DGIOT云云对接——第三方平台对接dgiot基本接口介绍

首页技术文章

file

[小 迪 导读]
随着大数据技术和智能显示技术的发展,数字可视化大屏设计已经成为IT信息领域一种普遍的数据展示应用场景。从政府的宏观政务决策,到企业的生产管理,从环保数据的实时监控,到电商平台的流量监控,都离不开数据大屏的身影。可视化数据大屏承载着各种组织对内信息共享、决策分析,对外信息公布、行业交流、会议现场展示等重任,被越来越广泛的应用。在数字化转型潮流中,dgiot能够提供海量的数据采集并通过dgiot统一接口为第三方提供设备信息的数据消费。

1.0 获取Token

1.1登录接口

接口名称: 登录接口
接口地址: https://prod.dgiotcloud.cn/iotapi/login
请求方法: POST

请求参数

参数 参数名称 类型 参数说明 是否必填项
username 用户名 String 系统账户
password 密码 String 系统账户密码
Json 示例:{"password": "dgiot_admin","username": "dgiot_admin"}

返回参数

参数 参数名称 类型 参数说明 是否必填项
username 用户名 String 系统账户
sessionToken 会话标识 String 系统请求唯一验证

Json 示例:{"sessionToken": "r:b2567201abe12b1581ebf5dd16839edd","username": "dgiot_admin"}

1.2 获取token

接口名称: 获得Token
接口地址: https://prod.dgiotcloud.cn/iotapi/token
请求方法: POST

请求参数

参数 参数名称 类型 参数说明 是否必填项
appid 应用名称 String 在SDK调用过程中唯一的一个应用标识
secret 应用密钥 String 调用API时的Token,用来验证请求合法性,请注意保密

返回参数

参数 参数名称 类型 参数说明 是否必填项
name 用户名 String 系统账户
access_token 会话标识 String 系统请求唯一验证
expires_in Token过期时间 Int Token过期时间单位:秒
desc 描述 String 描述

2.0查询Device parse数据

简要描述:

  • 获取当前设备parse数据

请求URL:

  • https://prod.dgiotcloud.cn/iotapi/classes/Device

请求方式:

  • GET

参数:

参数名 必选 类型 说明
order string 排序方式, 负为降序, eg: score,-name
limit integer limit, 显示多少条记录,显示100条记录 eg:100
skip integer skip, 从第几条记录开始
keys string 需要显示的字段,加count(*)则结果里面会显示总记录数, last_row为获取最后一条记录, eg: devaddr,status
include string include
where integer 过滤条件,eg: {"devaddr":{"$in":["842500EE"]}}
curl -X GET "https://prod.dgiotcloud.cn/iotapi/classes/Device?order=createdAt&limit=10&skip=0&keys=devaddr%2Cstatus&where=%7B%22devaddr%22%3A%7B%22%24in%22%3A%5B%22842500EE%22%5D%7D%7D" -H "accept: application/json" -H "authorization: Basic bGl1c2hvdXhpbjpsaXVzaG91eGlu"
curl -X GET "https://prod.dgiotcloud.cn/iotapi/classes/Device?order=createdAt&limit=10&skip=0&keys=devaddr%2Cstatus&where=%7B%22devaddr%22%3A%7B%22%24in%22%3A%5B%22842500EE%22%5D%7D%7D" -H "accept: application/json" -H "authorization: Basic bGl1c2hvdXhpbjpsaXVzaG91eGlu"

返回示例

{
"results": [
{
"devaddr": "842500EE",
"status": "ONLINE",
"objectId": "7f484ee521",
"createdAt": "2021-04-18T11:06:53.878Z",
"updatedAt": "2021-04-19T05:43:14.419Z",
"ACL": {
"role:admin": {
"read": true,
"write": true
}
}
}
]
}
{ "results": [ { "devaddr": "842500EE", "status": "ONLINE", "objectId": "7f484ee521", "createdAt": "2021-04-18T11:06:53.878Z", "updatedAt": "2021-04-19T05:43:14.419Z", "ACL": { "role:admin": { "read": true, "write": true } } } ] }

返回参数说明

备注

  • 更多返回错误代码请看首页的错误代码描述

3.0查询单个Device时序数据

简要描述:

  • 获取当前设备时序数据

请求URL:

  • https://prod.dgiotcloud.cn/iotapi/device

请求方式:

  • GET

参数:

参数名 必选 类型 说明
deviceid string 设备ID
order string 排序方式, 负为降序, eg: score,-name
limit integer limit, 显示多少条记录,显示100条记录 eg:100
skip integer skip, 从第几条记录开始
keys string 需要显示的字段,加count(*)则结果里面会显示总记录数, last_row为获取最后一条记录, eg: username,email
where integer 过滤条件,eg: {"createdat": {"$gte":"now - 10d"}}
curl -X GET "https://prod.dgiotcloud.cn/iotapi/device/69c7f9e376?order=createdAt&limit=10&skip=10&where=%7B%22createdat%22%3A%20%7B%22%24gte%22%3A%22now%20-%2010d%22%7D%7D" -H "accept: application/json" -H "authorization: Basic YWRtaW46c3dTV2lvdG4ybi5jb20="
curl -X GET "https://prod.dgiotcloud.cn/iotapi/device/69c7f9e376?order=createdAt&limit=10&skip=10&where=%7B%22createdat%22%3A%20%7B%22%24gte%22%3A%22now%20-%2010d%22%7D%7D" -H "accept: application/json" -H "authorization: Basic YWRtaW46c3dTV2lvdG4ybi5jb20="

返回示例

{
"results": [
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:27:02.577"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:27:12.582"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:27:22.512"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:27:32.451"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:27:42.515"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:27:52.389"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:28:02.390"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:28:12.454"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:28:22.360"
},
{
"activetotalenergy": 0,
"createdat": "2021-04-14 03:28:32.279"
}
]
}
{ "results": [ { "activetotalenergy": 0, "createdat": "2021-04-14 03:27:02.577" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:27:12.582" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:27:22.512" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:27:32.451" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:27:42.515" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:27:52.389" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:28:02.390" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:28:12.454" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:28:22.360" }, { "activetotalenergy": 0, "createdat": "2021-04-14 03:28:32.279" } ] }

返回参数说明

备注

  • 更多返回错误代码请看首页的错误代码描述

RESTful接口使用帮助

重复登录问题解决方案:

curl 是常用的命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。

它的功能非常强大,命令行参数多达几十种。其中 -u 参数可以用来设置服务器认证的用户名和密码。

  • $ curl -u 'demo:123456'

    上面命令设置用户名为demo,密码为123456。

以上文curl为例:

原:curl -X GET "https://prod.dgiotcloud.cn/iotapi/device/a47072cd8b?order=createdAt&limit=10&skip=10&where=%7B%22createdat%22%3A%20%7B%22%24gte%22%3A%22now%20-%2010d%22%7D%7D" -H "accept: application/json"
现:curl -u 'demo:123456' -X GET "https://prod.dgiotcloud.cn/iotapi/device/a47072cd8b?order=createdAt&limit=10&skip=10&where=%7B%22createdat%22%3A%20%7B%22%24gte%22%3A%22now%20-%2010d%22%7D%7D" -H "accept: application/json"
原:curl -X GET "https://prod.dgiotcloud.cn/iotapi/device/a47072cd8b?order=createdAt&limit=10&skip=10&where=%7B%22createdat%22%3A%20%7B%22%24gte%22%3A%22now%20-%2010d%22%7D%7D" -H "accept: application/json" 现:curl -u 'demo:123456' -X GET "https://prod.dgiotcloud.cn/iotapi/device/a47072cd8b?order=createdAt&limit=10&skip=10&where=%7B%22createdat%22%3A%20%7B%22%24gte%22%3A%22now%20-%2010d%22%7D%7D" -H "accept: application/json"

TDengine支持SQL语句:

为支持各种不同类型平台的开发,TDengine提供符合REST设计标准的API,即RESTful API。为最大程度降低学习成本,不同于其他数据库RESTful API的设计方法,TDengine直接通过HTTP POST 请求BODY中包含的SQL语句来操作数据库,仅需要一个URL。

http://<ip>:<PORT>/rest/sql
http://<ip>:<PORT>/rest/sql

curl语法如下:

curl -u username:password -d '<SQL>' <ip>:<PORT>/rest/sql
curl -u username:password -d '<SQL>' <ip>:<PORT>/rest/sql

注意:SQL语句中的数据表应提供数据库前缀

下面以查询最近十条记录为例

curl -H "accept: application/json" -u root:taosdata -d 'SELECT createdat FROM _3ea14b556a._d46d4340d9 order by createdat desc limit 10 ' http://prod.dgiotcloud.cn:6041/rest/sql
curl -H "accept: application/json" -u root:taosdata -d 'SELECT createdat FROM _3ea14b556a._d46d4340d9 order by createdat desc limit 10 ' http://prod.dgiotcloud.cn:6041/rest/sql

返回示例

{
"status":"succ",
"head":[
"createdat"
],
"data":[
[
"2021-04-20 03:09:42.737"
],
[
"2021-04-20 03:09:17.726"
],
[
"2021-04-20 03:08:51.004"
],
[
"2021-04-20 03:08:14.428"
],
[
"2021-04-20 03:07:48.258"
],
[
"2021-04-20 03:07:13.028"
],
[
"2021-04-20 03:06:47.026"
],
[
"2021-04-20 03:06:20.609"
],
[
"2021-04-20 03:05:44.695"
],
[
"2021-04-20 03:05:18.560"
]
],
"rows":10
}
{ "status":"succ", "head":[ "createdat" ], "data":[ [ "2021-04-20 03:09:42.737" ], [ "2021-04-20 03:09:17.726" ], [ "2021-04-20 03:08:51.004" ], [ "2021-04-20 03:08:14.428" ], [ "2021-04-20 03:07:48.258" ], [ "2021-04-20 03:07:13.028" ], [ "2021-04-20 03:06:47.026" ], [ "2021-04-20 03:06:20.609" ], [ "2021-04-20 03:05:44.695" ], [ "2021-04-20 03:05:18.560" ] ], "rows":10 }

[小 迪 点评]

  • dgiot支持对接第三方平台,为数字可视化大屏等第三方应用提供有力的数据保障。

想了解更多 dgiot 的具体细节,欢迎大家在GitHub上查看相关源代码。

上一篇:
上一篇:

加小迪为好友
即可加入交流群

点击填写表单
获得解决方案专家帮助
点击前往 GitHub
查看源代码