设备管理 IOTDM(联通用户专用)-设备绑定:示例

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

示例

调用IOTA_Bind()接口进行设备绑定。

1
2
3
4
5
6
7
8
9
//开发者调用该接口进行设备绑定 
ST_HW_DEVICE_INFO stDeviceInfo 
stDeviceInfo.pcNodeId = SN Number; 
stDeviceInfo.pcManufacturerId = Huawei; 
stDeviceInfo.pcDeviceType = Gateway; 
stDeviceInfo.pcModel = HW_GW101; 
stDeviceInfo.pcProtocolType = HuaweiM2M; 

IOTA_Bind(SN Number, &stDeviceInfo);

当设备成功绑定之后,Agent Lite会返回给UI如下几个参数,需要UI进行持久化存储,设备登录前需要提前进行配置

 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
//注册广播接收处理函数 
HW_BroadCastReg(IOTA_TOPIC_BIND_RSP, Device_RegResultHandler);
// 开发者注册该函数处理绑定结果 
HW_iNT Device_RegResultHandler(HW_UiNT uiCookie, HW_MSG pstMsg) 
{
    HW_cHAR *pcDeviceId;
    HW_cHAR *pcDeviceSecret;
    HW_cHAR *pcAppId;
    HW_cHAR *pcIoCMServerAddr;
    HW_UiNT uiIoCMServerPort;
    HW_cHAR *pcMqttServerAddr;
    HW_UiNT uiMqttServerPort;
    If (HW_SUC CES S != HW_MsgGetUint(pstMsg, EN_IOTA_BIND_IE_RESULT, 0)) 
    {
        Return 0;
    }
    pcDeviceId = HW_MsgGetStr(pstMsg, EN_IOTA_BIND_IE_DEVICEID);
    pcDeviceSecret = HW_MsgGetStr(pstMsg, EN_IOTA_BIND_IE_DEVICESECRET);
    pcAppId = HW_MsgGetStr(pstMsg, EN_IOTA_BIND_IE_APPID);
    pcIoCMServerAddr = HW_MsgGetStr(pstMsg, EN_IOTA_ BIND_IE_IOCM_ADDR );
    uiIoCMServerPort = HW_MsgGetUint(pstMsg, EN_IOTA_BIND_IE_IOCM_PORT, 0);
    pcMqttServerAddr = HW_MsgGetStr(pstMsg, EN_IOTA_ BIND_IE_IOCM_ADDR );
    uiMqttServerPort = HW_MsgGetUint(pstMsg, EN_IOTA_BIND_IE_IOCM_PORT, 0);
    Config_save(DeviceId,pcDeviceId);
    Config_save(DeviceSecret,pcDeviceSecret);
    Config_save(AppId,pcAppId);
    Config_save(IoCMAddr,pcIoCMServerAddr);
    Config_save(IoCMPort,pcIoCMServerPort);
    Config_save(MqttAddr,pcMqttServerAddr);
    Config_save(MqttPort,pcMqttServerPort);
    return 0;
}
support.huaweicloud.com/sdkreference-iot/iot_06_1108.html