下发关机指令

<p>下发关机指令流程:</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191410134236-1a565e049751.png" style="height:172px; width:498px" /></p> <p>下发开关机指令在串口协议中属于下行指令,在物模型协议中是通过服务调用来实现的;</p> <p>注意:服务调用和属性下发的区别,服务调用是设备一系列行为设置的合集,可以是多个属性设置的集合,也可以是非属性指令并且设备支持的行为指令合集;属性下发是针对物模型定义的可写属性,实现1个或者多个属性的远程设置。</p> <p>下行数据:</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="background-color:#ededed; vertical-align:top"> <p><strong>功能</strong></p> </td> <td style="background-color:#ededed; vertical-align:top"> <p><strong>设置关机</strong></p> </td> </tr> <tr> <td style="vertical-align:top"> <p><strong>串口数据</strong></p> </td> <td style="vertical-align:top"> <p>06 53 01</p> </td> </tr> <tr> <td style="vertical-align:top"> <p><strong>MQTT</strong></p> <p><strong>客户端</strong></p> </td> <td style="vertical-align:top"> <p>调用服务,权限:subscribe</p> <p>topic:{productKey}/{DeviceName}/sys/thing/service/PowerSwitch</p> <p>content:{&quot;method&quot;:&quot;thing.service.PowerSwitch&quot;,&quot;id&quot;:&quot;0002&quot;,&quot;params&quot;:{&quot; switch&quot;:1},&quot;version&quot;:&quot;1.0&quot;}</p> </td> </tr> </tbody> </table> <p>示例程序\example\ pa_iot_mqtt_uart中下行通信相关代码讲解:</p> <p>物模型回调函数实现如下,接收云端的服务调用数据,转换成串口数据包发送给温度控制器;</p> <pre> <code>static void on_sys_sub_callback(iot_mqttc_handle handle, void* params) {     iot_mqtt_sys_sub_event_data_t* msg_data = (iot_mqtt_sys_sub_event_data_t *)params;     char uartSendBuffer[UART_LEN_MAX] = {0};     cJSON* value = NULL;     cJSON* paramsdata = NULL;     if (!msg_data) {         return;     }     printf("receive sys sub message....\n");     printf("PayLoad:%s\n", (char *)msg_data-&gt;payload);     /*get commond from server*/     value = cJSON_Parse(msg_data-&gt;payload);     if (!value) {         printf("sys sub message payload is null.\n");         return;     }     paramsdata = cJSON_GetObjectItem(value, "params");     if (msg_data-&gt;type == OBJ_MODULE_GET_DEV_SERVER) {         /*execute service commond */         uart_data_from_json(uartSendBuffer, paramsdata);         printf("send buffer = %s,len = %d\n", uartSendBuffer, strlen(uartSendBuffer));         hfuart_send(HFUART0, uartSendBuffer, strlen(uartSendBuffer), UART_TIMEOUT);     }     if (value) {         cJSON_Delete(value);         value = NULL;     } }</code></pre> <p>运行结果如下:</p> <p>云端调用OpenAPI接口实现服务调用,参数如下:</p> <pre> <code>{        "productKey":"j0S1xxxxxxx",        "deviceName":"ccbfxxxxxx",        "identifier":"PowerSwitch",        "args":{               "switch":1        } }</code></pre> <p>LPB130接收云端指令打印结果如下:</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191410134542-14e180e89548.png" style="height:48px; width:554px" /></p> <p>串口发送的数据如下:</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191410134610-1ef3785794df.png" style="height:62px; width:554px" /></p>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询 - 7x24 小时

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

7x24 小时,急速解答

工单支持

解决云产品相关技术问题