数据采集交互图
1.初始化订阅
点击对应的设备,进行一个数据的订阅,mqtt发送的数据
[
{
"devicetype": "换算值",
"identifier": "conversion_flow",
"imgurl": "",
"name": "换算流量",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "m³/h"
},
{
"devicetype": "换算值",
"identifier": "conversion_head",
"imgurl": "",
"name": "换算扬程",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": ""
},
{
"devicetype": "换算值",
"identifier": "conversion_power",
"imgurl": "",
"name": "换算功率",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "kW"
},
{
"devicetype": "计算值",
"identifier": "effect",
"imgurl": "",
"name": "机组效率",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "%"
},
{
"devicetype": "计算值",
"identifier": "head",
"imgurl": "",
"name": "扬程",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "m"
},
{
"devicetype": "仪表数据",
"identifier": "power",
"imgurl": "",
"name": "功率",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "kW"
},
{
"devicetype": "仪表数据",
"identifier": "factor",
"imgurl": "",
"name": "功率因数",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": ""
},
{
"devicetype": "仪表数据",
"identifier": "current_c",
"imgurl": "",
"name": "电流_c",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "A"
},
{
"devicetype": "仪表数据",
"identifier": "current_b",
"imgurl": "",
"name": "电流_b",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "A"
},
{
"devicetype": "仪表数据",
"identifier": "current_a",
"imgurl": "",
"name": "电流_a",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "A"
},
{
"devicetype": "仪表数据",
"identifier": "vol",
"imgurl": "",
"name": "电压",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "V"
},
{
"devicetype": "仪表数据",
"identifier": "motorspeed",
"imgurl": "",
"name": "转速",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "r/min"
},
{
"devicetype": "仪表数据",
"identifier": "pressure_in",
"imgurl": "",
"name": "进口压力",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "KPa"
},
{
"devicetype": "仪表数据",
"identifier": "pressure_out",
"imgurl": "",
"name": "出口压力",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "KPa"
},
{
"devicetype": "仪表数据",
"identifier": "flow",
"imgurl": "/dgiot_file/devicething/ico/fa82a59201.flow.png?timestamp=1640852770146",
"name": "流量",
"number": "--",
"time": "2022-12-02 15:00:22",
"type": "float",
"unit": "m³/h"
}
]
2.数据采集
替换发送数据
```javascript
//conversion_flow:该数值为物模型的变量名
document.getElementsByClassName('conversion_flow')[1].getElementsByClassName('antd-PlainField')[0].innerHTML</p>
<pre><code>采集数据amis样例
```json
{
"type": "crud",
"id": "u:e609cd7a9561",
"api": {
"url": "/iotapi/amis/Device/${objectId}",
"method": "get",
"adaptor": "let list = []\r\nlet index = Math.floor(Math.random()*payload.data.profile.historicaldata.length)\r\nlist.push(payload.data.profile.historicaldata[index])\r\nlet rows = list\r\nlet columns = payload.data.profile.historicaldatacolumns\r\ncolumns.forEach(item =>{\r\n item.name = item.prop\r\n item.className = item.prop\r\n})\r\nlet data = {\r\n rows,\r\n columns,\r\n collect:rows\r\n}\r\nreturn {\r\n data,\r\n msg:\"ok\",\r\n status:0\r\n}\r\n"
},
"name": "collect",
"messages": {
},
"bulkActions": [
],
"itemActions": [
],
"placeholder": "-",
"syncLocation": false,
"perPageAvailable": [
10
],
"columnsTogglable": false
}
要求
1。添加采集数据初始化接口
2.格式要求
{
rows:[],
columns:[]
}
- rows: 为初始化的数据,需要一个默认值作为一个初始化的节点渲染,以便于后续mqtt发送消息时找到对应的节点进行内容替换
- columns:动态的表头 必要参数: label: 表头显示的名字,name:绑定对象的变量名,className:数据绑定的className,用以后续mqtt 替换内容进行查找的条件
- 数据样例:
{
"rows": [
{
watertemperature:"-",
flow:'-',
pressure_out:'-',
pressure_in:'-',
rotate:'-',
vol:'-',
current:'-',
power:'-',
head:'-'
}
],
"columns": [
{
"label": "水温度(°C)",
"prop": "watertemperature",
"name": "watertemperature",
"className": "watertemperature"
},
{
"label": "流量(m³/h)",
"prop": "flow",
"name": "flow",
"className": "flow"
},
{
"label": "出口压力(MPa)",
"prop": "pressure_out",
"name": "pressure_out",
"className": "pressure_out"
},
{
"label": "进口压力(MPa)",
"prop": "pressure_in",
"name": "pressure_in",
"className": "pressure_in"
},
{
"label": "转速(r/min)",
"prop": "rotate",
"name": "rotate",
"className": "rotate"
},
{
"label": "电压(V)",
"prop": "vol",
"name": "vol",
"className": "vol"
},
{
"label": "电流(A)",
"prop": "current",
"name": "current",
"className": "current"
},
{
"label": "功率(kW)",
"prop": "power",
"name": "power",
"className": "power"
},
{
"label": "扬程(m)",
"prop": "head",
"name": "head",
"className": "head"
},
{
"label": "机组效率(%)",
"prop": "effect",
"name": "effect",
"className": "effect"
}
]
}
## 3.数据采集下发
![file](http://dgiot-1253666439.cos.ap-shanghai-fsi.myqcloud.com/dgiot_web/doc_xxb/amis/1.png)
过程:增加一个控制下发的采集接口,点击按钮触发接口,后端发送要采集的数据
## 4.实时数据展示
![file](http://dgiot-1253666439.cos.ap-shanghai-fsi.myqcloud.com/dgiot_web/doc_xxb/amis/2.png)
- 实时数据替换
```javascript
//conversion_flow:该数值为物模型的变量名
document.getElementsByClassName('conversion_flow')[3].innerHTML
实时数据amis样例
{
"type": "crud",
"api": {
"url": "/iotapi/devicecard/${objectId}",
"method": "get",
"adaptor": "console.log('payload1111',payload)\r\nreturn {\r\n data:{\r\n items:payload.data\r\n },\r\n msg:'ok',\r\n status:0\r\n}"
},
"card": {
"body": [
{
"tpl": "<span style='color:#0000ff;margin-left:50px;font-size:24px' class='${identifier}'>${number}</span>",
"type": "tpl"
},
{
"name": "time",
"label": "时间"
}
],
"header": {
"title": "$name",
"avatar": "",
"subTitle": "$unit",
"avatarClassName": "pull-left thumb b-3x m-r"
}
},
"mode": "cards",
"messages": {
},
"draggable": true,
"placeholder": "暂无数据",
"silentPolling": true,
"perPageAvailable": [
10
]
}