本文借助示例Demo主要描述如何上报设备信息至云端。
运行示例程序,在数据模板模块上点击设备上线
按钮且设备成功上线后,点击设备信息上报
按钮,拼接设备信息参数,发布属性类型的Topic:
$thing/up/property/{ProductID}/{DeviceName}
示例代码如下:
JSONObject params = new JSONObject();
JSONObject label = new JSONObject(); //device label
label.put("version", "v1.0.0");
label.put("company", "tencent");
params.put("module_hardinfo", "v1.0.0");
params.put("module_softinfo", "v1.0.0");
params.put("fw_ver", "v1.0.0");
params.put("imei", "0");
params.put("mac", "00:00:00:00");
params.put("device_label", label);
if(Status.OK != mDataTemplateSample.propertyReportInfo(params)) {
mParent.printLogInfo(TAG, "property report failed!", mLogInfoText, TXLog.LEVEL_ERROR);
}
观察Logcat日志。
I/com.tencent.iot.hub.device.java.core.mqtt.TXMqttConnection: Starting publish topic: $thing/up/property/LWVUL5SZ2L/light1 Message: {"method":"report_info","clientToken":"LWVUL5SZ2Llight13","params":{"module_hardinfo":"v1.0.0","module_softinfo":"v1.0.0","fw_ver":"v1.0.0","imei":"0","mac":"00:00:00:00","device_label":{"version":"v1.0.0","company":"tencent"}}}
D/TXDataTemplateFragment: onPublishCompleted, status[OK], topics[[$thing/up/property/LWVUL5SZ2L/light1]], userContext[], errMsg[publish success]
以上是成功发布设备信息上报Topic的日志。