
**[小 迪 导读]**:在控制设备的过程中,经常会碰到下面这些问题:
老式方案 |
dgiot基于dlink协议配置同步方案 |
---|
平台根据实际情况控制开关机 |
平台远程控制设备同步开关机状态 |
老式方案缺点:
- 当平台控制指令没有发下去时,平台需要再次点击发出控制指令,较浪费人力
dgiot配置同步方案优点:
- 设备上电,设备状态全权由平台管理员控制即平台控制值,例如:平台为关机,现场设备即使开机平台将会自动下发关机指令,将设备再次关机。
整体交互图
方案执行步骤
1.在平台上创建产品,如下图为例。

#### 2.在产品详情的物模型中创建设备上传的"key":"value"对应的物模型,如下图为例。

#### 3.在产品详情的可视化中添加低代码,如下图为例。

#### 4.点击设计编辑低代码,先编辑成产品的低代码用以添加平台的key与上传设备的key进行关联,如下图。



```
产品低代码例子,以实际产品为准:
{
"type": "form",
"api": {
"url": "iotapi/classes/Device/parse_objectid",
"method": "put",
"headers": {
"store": "localStorage",
"dgiotReplace": "parse_objectid"
},
"dataType": "json",
"requestAdaptor": "return {\r\n \"status\":0,\r\n \"msg\":\"\",\r\n \"data\":response\r\n }"
},
"body": [
{
"id": "u:52fbc3355570",
"mode": "inline",
"name": "Ctrl",
"type": "switch",
"label": "开关机",
"onText": "开",
"option": "",
"offText": "关",
"trueValue": 1,
"falseValue": 0,
"validateApi": {
"url": "iotapi/amis/Product/b5f75b59a3",
"method": "put",
"requestAdaptor": "return {\r\n ...api,\r\n data:{\r\n profile:{\r\n Ctrl:api.data.Ctrl \r\n }\r\n }\r\n}"
},
"submitOnChange": true
}
],
"title": "开关机控制器",
"trueValue": true,
"falseValue": false,
"submitText": "",
"optionAtLeft": false
}
```
#### 5.在产品详情的可视化中找到刚刚创建的低代码,点击预览,点击一下开关机添加平台key,如下图。

#### 6.在产品详情的物模型中找到刚刚创建的物模型,点击编辑,关联平台key与设备key,如下图。

#### 7.在产品详情的可视化中找到刚刚创建的低代码,点击设计,修改为设备的低代码,如下图。

```
设备低代码示例:
{
"type": "form",
"api": {
"url": "iotapi/classes/Device/parse_objectid",
"method": "put",
"headers": {
"store": "localStorage",
"dgiotReplace": "parse_objectid"
},
"dataType": "json",
"requestAdaptor": "return {\r\n \"status\":0,\r\n \"msg\":\"\",\r\n \"data\":response\r\n }"
},
"body": [
{
"id": "u:52fbc3355570",
"mode": "inline",
"name": "Ctrl",
"type": "switch",
"label": "开关机",
"onText": "开",
"option": "",
"offText": "关",
"trueValue": 1,
"falseValue": 0,
"validateApi": {
"url": "iotapi/amis/Device/parse_objectid",
"method": "put",
"headers": {
"store": "localStorage",
"dgiotReplace": "parse_objectid"
},
"requestAdaptor": "return {\r\n ...api,\r\n data:{\r\n profile:{\r\n Ctrl:api.data.Ctrl \r\n }\r\n }\r\n}"
},
"submitOnChange": true
}
],
"title": "开关机控制器",
"trueValue": true,
"falseValue": false,
"submitText": "",
"optionAtLeft": false
}
```
#### 8.设备模拟登录,方式一:MQTTX登录;方式二:ip:18083登录,用户名:admin,密码:public
##### 方式一:MQTTX登录

##### 方式二:ip:18083登录,用户名:admin,密码:public

用户名及密码获取方式,如下图:

#### 9.设备数据模拟上报,方式一:MQTTX上报;方式二:ip:18083上报
```
dgiot上报数据Topic
$dg/thing/{ProductId}/{DeviceAddr}/properties/report
dgiot下发控制命令Topic
$dg/device/{ProductId}/{DeviceAddr}/profile
```
可以在设备详情查看其对应Topic,如下图:


##### 方式一:MQTTX上报

###### 上报数据

###### 订阅到的控制指令

##### 方式二:ip:18083上报

###### 上报数据

###### 订阅到的控制指令

10.设备配置同步实现,以ip:18083为例
平台设置为开机,如下图

##### ip:18083模拟上报状态值为0(关机的状态),平台自动下发开机命令,如下图

##### 平台设置为关机,如下图

##### ip:18083模拟上报状态值为1(开机的状态),平台自动下发关机命令,如下图

- dgiot平台配置同步下发控制指令。
- 在成本方面dgiot为降低用户使用成本,降低运维成本。
打开App,阅读手记