设备管理 IOTDM(联通用户专用)-发布数据:示例

时间:2024-07-03 16:54:05

示例

开发者调用数据发布接口。

1
DataTransService. mqttDataPub1211, "/huawei/v1/devices/336d9bac-9ebf-44e9-95cf-efac5f05da3a/services/Storage", 1, bstrBody);

开发者调用数据发布接口前需要实现Agent Lite提供的观察者接口。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Subscribe implements MyObserver {
    public Subscribe (Observable dataTransService) {
        dataTransService. registerObserver (this);
    }
    @Override
    public void update(IotaMessage arg0) {
        // TODO Auto-generated method stub
        System.out.println("AgentLiteDataTrans收到通知:" + arg0);
        int mMsgType = arg0.getMsgType();
        switch(mMsgType) {
            //数据上报应答
            case IodevService.IODEV_MSG_DATA_REPORT_RSP:
            getDataReportAnswer(arg0);
            break;
            //被动接收命令
            case IodevService.IODEV_MSG_RECEIVE_CMD:
            getCmdReceive(arg0);
            break;
            //MQTT消息推送
            case IodevService.IODEV_MSG_MQTT_PUB_RSP:
            //logoutResultAction(iotaMsg);
            break;
            case IodevService.IODEV_MSG_MQTT_SUB_RSP:
            //TopicSubcribeResultAction(iotaMsg);
            break;
            case IodevService.IODEV_MSG_MQTT_DATA_RECV_RSP:
            //DataRecvAction(iotaMsg);
            break;
            default:
            break;
        }
    }
support.huaweicloud.com/sdkreference-iot/iot_06_1220.html