上个专栏介绍了很多关于FlexManager设备云端数据的各种操作,相信大家都有看了。本专栏将就怎么使用设备云数据库的数据进行自主客户端APP开发的一些知识点做一下细致讲解。当然,自始至终,我只讲自己擅长的领域,只分享某一块自己真实应用的体验和经验。本篇讲解使用okhttp通过apiBaseUrl获取FlexManager监控点数据。
提示:以下是本篇文章正文内容,下面案例可供参考
【apiBaseUrl】该接口可用于用户获取监控点值。
[apiBaseUrl]v2/dmon/value/get?boxNo={boxNo}
参数名 | 数据类型 | 参数详情 |
---|---|---|
apiBaseUrl | string | 公有云地址为:http://fbcs101.fbox360.com/api/,若私有云的话改为对应的私有云配置域名。 |
boxNo | string | FBox的序列号 |
请求方式为POST。
请求Headers如下所示:
参数名 | 数据类型 | 参数详情 |
---|---|---|
Authorization | string | Bearer+ 空格+登录接口中获得的access_token |
请求的Body为:
JSON对象
字段名 | 类型 | 描述 |
---|---|---|
ids | jarray | 监控点id集合,与names二选一,使用名称优先,少于100个元素。(优先使用ids参数传参) |
timeOut | int | 最大读取超时,null为取服务器默认值(6000ms) |
groupnames | jarray | 用于不同组下存在同名监控点的情况。与监控点名称集合联合使用,组名与监控点名称一 一对应 |
names | jarray | 监控点名称集合,与ids二选一,使用名称优先,少于100个元素。 |
响应成功后返回JSON数组:
字段名 | 类型 | 描述 |
---|---|---|
id | string | 监控点Id |
timestamp | datetime | 时间戳,由于从缓存里拉的数据,所以需要时间戳来判断是否已经过期,UTC时间 |
dataType | int | 数据类型,见附录二 |
value | string/int | 值,根据数据类型返回值类型。 |
name | string | 监控点名称 |
boxId | long | 盒子Id |
status | int | 监控点状态,0:正常,1:无数据,2:超时,3:错误,4:Socket异常,5:FDS错误,16:未完成 |
connState | int | 盒子连接状态, 0:未知 , 1:已连接 ,2:超时, 3:断开 |
connStateTimestamp | datatime | 盒子的上线时间 |
参数名 | 参数描述 |
---|---|
200 | 执行成功 |
401 | accessToken过期 |
400 | 错误信息在HTTP Header里[X-FBox-Code],详细见附录三 |
404 | 接口不存在,请检查URL |
429 | 访问接口频率过快,详情见429状态码 |
使用请求地址URL:[apiBaseUrl]v2/dmon/value/get?boxNo={boxNo},加入apiBaseUrl、boxNo后,最终请求地址为http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300222032522,如图所示:
然后请求Headers为Bearer+ 空格+登录接口中获得的access_token,如图所示:
access_token要去登录请求里边获取,前面一篇已经讲过了,如图所示来操作:
请求一波获取最新access_token,然后粘贴或者替换到分组下所有数据监控点请求中的Authorization,然后就可以执行请求了。
最后请求的body设置,其json数据如下:
{
"names":["输送手动状态","输送自动状态","输送EDI水箱液位","混床前压力1","超滤前压力1","超滤后压力1","混床前压力2","超滤前压力2","超滤后压力2","回水电阻1","回水电阻2","回水流量1","回水流量2","输送泵1-1报警","输送泵1-2报警","输送泵2-1报警","输送泵2-2报警"],
"graoupnames":["输送运行参数"],
"timeout":null
}
我们先来看看FlexManager中的数据点位实时数据情况,如图所示:
响应成功后接口返回的这个设备输送运行参数监控点数据如下所示:
[
{
"id": "251608640135372207",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 0,
"name": "输送手动状态",
"value": 1,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251608640135372209",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 0,
"name": "输送自动状态",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251622487291336316",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "输送EDI水箱液位",
"value": 78.48456,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "256050870111706871",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "混床前压力1",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "256050892302720783",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "超滤前压力1",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251702200437316933",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "超滤后压力1",
"value": -0.004557168,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251702241141988995",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "混床前压力2",
"value": 0.0028211041,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251702256326418153",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "超滤前压力2",
"value": 0.006799584,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251702270205370103",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "超滤后压力2",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251608640122789225",
"timestamp": "2022-10-22T23:24:58.0129216Z",
"dataType": 16,
"name": "回水电阻1",
"value": 9.616957,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251622955687091526",
"timestamp": "2022-10-22T23:24:58.0129216Z",
"dataType": 16,
"name": "回水电阻2",
"value": 4.9705615,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251700808990594345",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "回水流量1",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251700891185321401",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 16,
"name": "回水流量2",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251608640129080713",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 0,
"name": "输送泵1-1报警",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251702372229714657",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 0,
"name": "输送泵1-2报警",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251702389355057912",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 0,
"name": "输送泵2-1报警",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
},
{
"id": "251702403323138824",
"timestamp": "2022-10-22T23:23:57.9728361Z",
"dataType": 0,
"name": "输送泵2-2报警",
"value": 0,
"boxId": "4969255108963659325",
"status": 0,
"connState": 1,
"connStateTimestamp": "2022-10-22T09:16:26.1114341Z"
}
]
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"names\":[\"输送手动状态\",\"输送自动状态\",\"输送EDI水箱液位\",\"混床前压力1\",\"超滤前压力1\",\"超滤后压力1\",\"混床前压力2\",\"超滤前压力2\",\"超滤后压力2\",\"回水电阻1\",\"回水电阻2\",\"回水流量1\",\"回水流量2\",\"输送泵1-1报警\",\"输送泵1-2报警\",\"输送泵2-1报警\",\"输送泵2-2报警\"],\r\n \"graoupnames\":[\"输送运行参数\"],\r\n \"timeout\":null\r\n}");
Request request = new Request.Builder()
.url("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=300222032522")
.post(body)
.addHeader("Authorization", "Bearer 空格后+你的登录access_token ")
.build();
Response response = client.newCall(request).execute();
以上就是今天要讲的内容,本文仅仅介绍了通过apiBaseUrl获取FlexManager监控点数据,而FlexManager提供了大量的API调用,同学们可以再继续深入了解一下本篇以后的内容。