Adding a Device

API Function

This API is used to add a device that accesses the IoT platform through the gateway. After the device is connected to the IoT platform, the IoT platform will assign a unique logical ID to the device.

API Description

1
public static boolean addDevice(int cookie, IotaDeviceInfo deviceInfo);

Class

HubService

Parameter Description

Parameter

Mandatory or Optional

Type

Description

cookie

Optional

int

The value ranges from 1 to 65535.

deviceInfo

Mandatory

IotaDeviceInfo

Device information.

IotaDeviceInfo:

Parameter

Mandatory or Optional

Type

Description

nodeId

Mandatory

String

Unique identifier of a device managed by the gateway connected to the IoT platform. The identifier is provided by the device itself.

name

Optional

String

Name of the device.

description

Optional

String

Description of the device.

manufacturerId

Mandatory

String

Identifier of a manufacturer.

manufacturerName

Optional

String

Name of the manufacturer.

mac

Optional

String

MAC address of the device.

location

Optional

String

Location of the device.

deviceType

Mandatory

String

Type of the device.

model

Mandatory

String

Model of the device.

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

swVersion

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.

fwVersion

Optional

String

Firmware version.

hwVersion

Optional

String

Hardware version.

protocolType

Mandatory

String

Protocol type (Z-Wave).

bridgeId

Optional

String

Identifier of the bridge through which the device connects to the IoT platform.

status

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

mute

Optional

String

Whether the device is muted.

  • TRUE
  • FALSE

Return Value

Return Value

Description

true

Success

false

Failure

Return values only show API calling results. For example, the return value true indicates that the API is called successfully but does not indicate that the device is added successfully. The device is added successfully only after the HubService broadcast is received.

Example

Call this API to add a device.

1
HubService.addDevice(29011, new IotaDeviceInfo("nodeId", "manufacturerId", "deviceType", "model", "protocolType"));

Implement the observer API provided by the AgentLite before calling this API.

 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
public class AgentliteHub implements MyObserver {
    public AgentliteHub (Observable hubService) {
        hubService. registerObserver (this);
    }
//Receive a device adding response.
    @Override
    public void update(IotaMessage arg0) {
        // TODO Auto-generated method stub
        System.out.println("Receive a notification from HubService:" + arg0);
        int mMsgType = arg0.getMsgType();
        switch(mMsgType) {
//Receive a device adding response.
            case IodevService.IODEV_MSG_ADD_DEVICE_RSP:
            getAddDeviceAnswer(arg0);
            break;
//Receive a device deletion response.
            case IodevService.IODEV_MSG_RMV_DEVICE_RSP:
            getRmvDeviceAnswer(arg0);
            break;
//Receive a device status update response.
            case IodevService.IODEV_MSG_UPDATE_DEVSTATUS_RSP:
            getUpdateStatusAnswer(arg0);
            break;
            case IodevService.IODEV_MSG_RECEIVE_CMD:
            getUnbindAnswer(arg0);
            break;
            default:
            break;
        }
    }