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

ST_IOTA_DEVICE_INFO

Device information. The value must end with \0.

ST_IOTA_DEVICE_INFO:

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.

  • For a directly connected device, the value must be the same as the model defined in the product model.
  • For a Z-Wave device, the model is in the hexadecimal format of productType + productId (padded with zeros if required), for example, 001A-0A12.

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.

  • ONLINE: The device is online.
  • OFFLINE: The device is offline.

statusDetail

Optional

String

Details about the device status. If pcStatus is specified, this parameter is mandatory.

Value:

  • None
  • CONFIGURATION_PENDING
  • COMMUNICATION_ERROR
  • CONFIGURATION_ERROR
  • BRIDGE_OFFLINE
  • FIRMWARE_UPDATING
  • DUTY_CYCLE
  • NOT_ACTIVE

pcMute

Optional

String

Whether the device is muted.

  • TRUE
  • FALSE

Return Value

For details, see Function Return Values.

Output

Broadcast Name

Broadcast Parameter

Member

Description

IOTA_TOPIC_HUB_ADDDEV_RSP

HW_MSG object

EN_IOTA_HUB_IE_TYPE

Device addition result. If the addition is successful, the device ID is returned.

EN_IOTA_HUB_IE_TYPE:

Enumerated Item

Value

Type

Description

EN_IOTA_HUB_IE_RESULT

0

EN_IOTA_HUB_RESULT_TYPE

Device addition or deletion result.

EN_IOTA_HUB_IE_DEVICEID

1

String

Identifier of the device assigned after successful addition.

EN_IOTA_HUB_RESULT_TYPE:

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).