上报温度

<p>上报温度流程:</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191410133316-1710b9f1903b.png" style="height:186px; width:497px" /></p> <p>根据串口通信协议,温度传感器上报给LPB130的参数类型有温度、故障状态,串口接收到设备状态后转换成物模型的属性上报或者事件上报,即可实现将云端对设备状态的远程获取。</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>03 54 21</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>上报属性,权限:publish</p> <p>topic:{productKey}/{DeviceName}/sys/thing/event/property/post</p> <p>content:{&quot;id&quot;:&quot;00002&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;params&quot;:{&quot;temperature&quot;:33},&quot;method&quot;:&quot;thing.event.property.post}</p> </td> </tr> </tbody> </table> <p>示例程序\example\ pa_iot_mqtt_uart中属性上报及事件上报相关代码讲解</p> <p>1、文件中定义物模型类型,用于区分串口发送的数据归属的物模型类型。</p> <pre> <code>typedef enum objTypes {     PROPERTY = 0,     EVENT = 1,     SERVICE = 2 } objTypes;</code></pre> <p>2、 文件中实现串口的回调,串口发送的数据需要区分属性上报和事件上报;</p> <pre> <code>/*data uart callback */ static int uart_recv_callback(uint32_t event, char *data, uint32_t len, uint32_t buf_len) { static char uart_data[UART_LEN_MAX] = {0}; cJSON* param_json = NULL; objTypes type = -1; memcpy(uart_data, data, len); uart_data[len] = '\0'; printf("[%d]uart recv %d bytes data=%s\n", event, len, uart_data); param_json = cJSON_CreateObject(); type = uart_data_to_json(uart_data, param_json); if (type == PROPERTY) { iot_mqtt_obj_module_request(mqtt_client_test_handle,OBJ_MODULE_DEV_ATTR_POST, param_json, NULL); } else if (type == EVENT) { iot_mqtt_obj_module_request(mqtt_client_test_handle,OBJ_MODULE_DEV_EVENT_POST, param_json,EVENT_IDENTIFER); } else { printf("uart command is illegal"); } if (param_json) { cJSON_Delete(param_json); param_json = NULL; } return len; } </code></pre> <p>本地通过uart0串口发送数据03 54 21,模拟设备上报温度33℃。</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191410133539-1c8671d7932d.png" style="height:149px; width:554px" /></p> <p>本地debug口打印结果如下:</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191410133553-148bc1829d19.png" style="height:49px; width:554px" /></p> <p>云端温度更新:</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20191410133757-1d0649de9003.png" style="height:190px; width:296px" /></p>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询 - 7x24 小时

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

7x24 小时,急速解答

工单支持

解决云产品相关技术问题