Adding a Device
API Function
This API is used to add a device that accesses the platform through a gateway. After the device is connected to the platform, the platform will assign a unique logical ID to the device.
API Description
1 | HW_INT IOTA_HubDeviceAdd(HW_UINT uiCookie, const ST_IOTA_DEVICE_INFO *pstDeviceInfo);
|
Parameter Description
| Parameter | Mandatory or Optional | Type | Description |
|---|---|---|---|
| uiCookie | Optional | HW_UINT | The value ranges from 1 to 65535. |
| pstDeviceInfo | Mandatory | Device information. The value must end with \0. |
| Parameter | Mandatory or Optional | Type | Description |
|---|---|---|---|
| pcNodeId | Mandatory | String | Unique identifier of a device managed by the gateway connected to the platform. The identifier is provided by the device itself. |
| pcName | Optional | String | Name of the device. |
| pcDescription | Optional | String | Description of the device. |
| pcManufacturerId | Mandatory | String | Identifier of a manufacturer. |
| pcManufacturerName | Optional | String | Name of the manufacturer. |
| pcMac | Optional | String | MAC address of the device. |
| pcLocation | Optional | String | Location of the device. |
| pcDeviceType | Mandatory | String | Type of the device. |
| pcModel | Mandatory | String | Model of the device.
|
| pcSwVersion | Optional | String | Software version. For a Z-Wave device, the software version is in the format of major version.minor version, for example, 1.1. |
| pcFwVersion | Optional | String | Firmware version. |
| pcHwVersion | Optional | String | Hardware version. |
| pcProtocolType | Mandatory | String | Protocol type (Z-Wave). |
| pcBridgeId | Optional | String | Identifier of the bridge through which the device connects to the platform. |
| pcStatus | Optional | String | Status of the device.
|
| statusDetail | Optional | String | Details about the device status. If pcStatus is specified, this parameter is mandatory. Value:
|
| pcMute | Optional | String | Whether the device is muted.
|
Return Value
For details, see Function Return Values.
Output
| Broadcast Name | Broadcast Parameter | Member | Description |
|---|---|---|---|
| IOTA_TOPIC_HUB_ADDDEV_RSP | HW_MSG object | Device addition result. If the addition is successful, the device ID is returned. |
| Enumerated Item | Value | Type | Description |
|---|---|---|---|
| EN_IOTA_HUB_IE_RESULT | 0 | Device addition or deletion result. | |
| EN_IOTA_HUB_IE_DEVICEID | 1 | String | Identifier of the device assigned after successful addition. |
| Enumerated Item | Value | Description |
|---|---|---|
| EN_IOTA_HUB_RESULT_SUCCESS | 0 | The device is added or deleted. |
| EN_IOTA_HUB_RESULT_DEVICE_EXIST | 1 | The device already exists. |
| EN_IOTA_HUB_RESULT_DEVICE_NOTEXIST | 2 | The device does not exist. |
| EN_IOTA_HUB_RESULT_DEVICE_FAILED | 255 | The execution fails. |
Example
1 2 3 4 5 6 7 8 9 | // Call this API to add a device.
ST_IOTA_DEVICE_INFO stDeviceInfo
stDeviceInfo.pcNodeId = "SN Number";
stDeviceInfo.pcManufacturerId = "Huawei";
stDeviceInfo.pcDeviceType = "Camera";
stDeviceInfo.pcModel = "HW_CAM101";
stDeviceInfo.pcProtocolType = "ONVIF";
IOTA_HubDeviceAdd(29011, &stDeviceInfo);
|
The device waits for the result.
1 2 3 4 5 6 7 8 9 10 11 12 | // Call this API to register the function for subsequent processing after the device is added.
HW_iNT Device_AddResultHandler(HW_UiNT uiCookie, HW_MSG pstMsg)
{
uiResult = HW_MsgGetUint(pstMsg, EN_IOTA_HUB_IE_RESULT);
if (EN_IOTA_HUB_RESULT_SUCCESS != uiResult)
{
// retry with uiCookie
return 0;
}
return 0;
}
// Bind the broadcast reception processing function HW_BroadCastReg ("IOTA_TOPIC_HUB_ADDDEV_RSP", Device_AddResultHandler).
|
Last Article: Managing an Indirectly Connected Device
Next Article: Updating the Device Status
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.