Updated on 2022-02-24 GMT+08:00

Registering a Device (Verification Code Mode)

Typical Scenario

Before a device accesses the IoT platform by using verification code, an NA needs to call this API to register the device with the IoT platform and set a unique identification code of the device (such as the IMEI) as the verification code. Then, the device can use the unique identification code to get authenticated and connect to the IoT platform.

API Function

This API is used by an NA to register a device with the IoT platform. After registration, the device can connect to the IoT platform.

API Description

1
def regDirectDevice(self, rddInDto, appId, accessToken)

Class

DeviceManagement

Parameter Description

Parameter

Mandatory or Optional

Type

Location

Description

rddInDto

Mandatory

RegDirectDeviceInDTO

body

For details, see RegDirectDeviceInDTO structure.

appId

Optional

String

query

If the device belongs to the current application, set this parameter to None. Otherwise, set this parameter to the ID of the authorized application.

accessToken

Mandatory

String

header

This parameter is set to the value of the access token obtained by calling the Authentication API.

RegDirectDeviceInDTO structure

Parameter

Mandatory or Optional

Type

Location

Description

customFields

Optional

List<CustomField>

Body

User-defined field list. Users can set customized fields.

deviceInfo

Optional

DeviceInfoDTO

Body

Specifies information about the device.

deviceInfo2

Optional

DeviceInfo2

Body

Indicates other device information.

deviceName

Optional

String(256)

Body

Specifies the name of a device.

endUserId

Optional

String(256)

Body

Identifies an end user.

In the NB-IoT solution, this parameter is set to the IMSI of the device. In the Smart Home solution, this parameter is set to the application account.

groupId

Optional

String(256)

Body

Identifies the device group to which a device belongs.

imsi

Optional

String(1-64)

Body

Indicates the IMSI of an NB-IoT device.

isSecure

Optional

Boolean

Body

Indicates whether the device is secure. The default value is false.

  • true: The device is secure.
  • false: The device is not secure.
NOTE:

If a user needs to register a secure device, this parameter must be specified.

location

Optional

Location

Body

Indicates the device location.

nodeId

Mandatory

String(256)

Body

Uniquely identifies a device. The value of this parameter must be the same as the device ID reported by the device. Generally, the MAC address, serial number, or IMEI is used as the node ID.

NOTE:

When the IMEI is used as the node ID, the node ID varies depending on the chip provided by the manufacturer.

  • The unique identifier of a Qualcomm chip is urn:imei:xxxx, where xxxx is the IMEI.
  • The unique identifier of a HiSilicon chip is the IMEI.
  • For details on the unique identifiers of chipsets provided by other manufacturers, contact the module manufacturers.

psk

Optional

String(8-32)

Body

If the pre-shared key (PSK) is specified in the request, the IoT platform uses the specified PSK. If the PSK is not specified in the request, the PSK is generated by the IoT platform. The value is a string of characters, including upper-case letters A to F, lower-case letters a to f, and digits 0 to 9.

tags

Optional

List<TagDTO2>

Body

Indicates the tag of a device.

timeout

Optional

Integer(>=0)

Body

Indicates the validity period for device registration. When this API is called to register a device, the device can be bound within the validity period. If the device is not bound within the validity period, the registration information will be deleted.

The value ranges from 0 to 2147483647. If this parameter is set to 0, the device verification code is always valid. (The recommended value is 0.)

The default value is 180. The default value can be configured. For details, contact the IoT platform maintenance personnel.

Unit: second

verifyCode

Conditionally optional

Mandatory

String(256)

body

Indicates the verification code of the device. If this parameter is specified in the request, it is returned in the response. If this parameter is not specified in the request, it is automatically generated by the IoT platform.

In the NB-IoT solution, this parameter is mandatory and must be set to the same value as nodeId.

productId

Optional

String(256)

Body

Identifies the product to which the device belongs.

account

Optional

String

Body

Indicates the IPC device account.

CustomField structure

Parameter

Mandatory or Optional

Type

Location

Description

fieldName

Optional

String(256)

Body

Indicates the field name.

fieldType

Optional

String(256)

Body

Indicates the field type.

fieldValue

Optional

String(256)

Body

Indicates the field value.

DeviceInfoDTO structure

Parameter

Mandatory or Optional

Type

Location

Description

nodeId

Optional

String(256)

Body

Identifies a device.

name

Optional

String(256)

Body

Specifies the name of a device.

description

Optional

String(2048)

Body

Indicates the device description.

manufacturerId

Optional

String(256)

Body

Uniquely identifies a manufacturer.

manufacturerName

Optional

String(256)

Body

Indicates the manufacturer name.

mac

Optional

String(256)

Body

Indicates the MAC address of the device.

location

Optional

String(2048)

Body

Indicates the device location.

deviceType

Optional

String(256)

Body

Indicates the device type. The upper camel case is used, for example, MultiSensor, ContactSensor, and CameraGateway.

model

Mandatory

String(256)

Body

Indicates the device model.

In Z-Wave, the format is productType + productId. The value is a hexadecimal value in the format of XXXX-XXXX. Zeros are added if required, for example, 001A-0A12. The format in other protocols is still to be determined.

swVersion

Optional

String(256)

Body

Indicates the software version of the device.

In Z-Wave, the format is major version.minor version, for example, 1.1.

fwVersion

Optional

String(256)

Body

Indicates the firmware version of the device.

hwVersion

Optional

String(256)

Body

Indicates the hardware version of the device.

protocolType

Optional

String(256)

Body

Indicates the protocol type used by the device. The value options are CoAP, huaweiM2M, Z-Wave, ONVIF, WPS, Hue, WiFi, J808, Gateway, ZigBee, and LWM2M.

bridgeId

Optional

String(256)

Body

Identifies the bridge through which the device accesses the IoT platform.

status

Optional

String

Body

Indicates whether the device is online. The value options are ONLINE, OFFLINE, INBOX, and ABNORMAL.

statusDetail

Optional

String(256)

Body

Indicates the device status details, which vary according to the value of status.

  • When status is ONLINE, the value options are NONE, COMMUNICATION_ERROR, CONFIGURATION_ERROR, BRIDGE_OFFLINE, FIRMWARE_UPDATING, DUTY_CYCLE, and NOT_ACTIVE.
  • When status is OFFLINE, the value options are NONE and CONFIGURATION_PENDING.

mute

Optional

String

Body

Indicates whether the device is in the frozen state. Based on the value of this parameter, the IoT platform determines whether to manage and store data reported by the device.

  • TRUE: The device is in the frozen state.
  • FALSE: The device is not in the frozen state.

supportedSecurity

Optional

String

Body

Indicates whether the security mode is supported.

  • TRUE: The security mode is supported.
  • FALSE: The security mode is not supported.

isSecurity

Optional

String

Body

Indicates whether the security mode is enabled.

  • TRUE: The security mode is enabled.
  • FALSE: The security mode is disabled.

signalStrength

Optional

String(256)

Body

Indicates the signal strength of the device.

sigVersion

Optional

String(256)

Body

Indicates the SIG version of the device.

serialNumber

Optional

String(256)

Body

Indicates the serial number of the device.

batteryLevel

Optional

String(256)

Body

Indicates the battery level of the device.

NOTE:

When the device status information is reported to the IoT platform, status and statusDetail must be included. It is recommended that statusDetail be used only for display but not for logical judgment.

DeviceInfo2 structure

Parameter

Mandatory or Optional

Type

Location

Description

region

Optional

String(256)

Body

Indicates the region where the device is located.

timezone

Optional

String(256)

Body

Specifies the time zone where a device is located.

activeServiceCount

Optional

Integer

Body

Indicates the number of active services of the device.

Location structure

Parameter

Mandatory or Optional

Type

Location

Description

accuracy

Optional

Double

Body

Indicates the accuracy. The minimum value is 0.

crashInformation

Optional

String

Body

Indicates the emergency information.

description

Optional

String

Body

Indicates the location description.

heading

Optional

String

Body

Indicates the direction information.

language

Optional

String

Body

Indicates the language.

latitude

Optional

Double

Body

Indicates the latitude of the device. The value ranges from -90 to 90.

longitude

Optional

Double

Body

Indicates the longitude of the device. The value ranges from -180 to 180.

numberOfPassengers

Optional

String

Body

Indicates the number of passengers.

region

Optional

String

Body

Indicates the region where the device is located.

time

Optional

DateTime

Body

Indicates the time information.

vehicleSpeed

Optional

String

Body

Indicates the vehicle speed.

TagDTO2 structure

Parameter

Mandatory or Optional

Type

Location

Description

tagName

Mandatory

String(1-128)

body

Indicates the tag name.

tagValue

Mandatory

String(1-1024)

body

Indicates the tag value.

Return Value

RegDirectDeviceOutDTO structure

Parameter

Type

Description

deviceId

String(256)

Uniquely identifies a device.

verifyCode

String(256)

Indicates a verification code that can be used by the device to obtain the device ID and password. If this parameter is specified in the request, it is returned in the response. If this parameter is not specified in the request, it is automatically generated by the IoT platform.

timeout

Number

Indicates the validity period of the verification code, in seconds. The device must connect to the IoT platform within this period.

psk

String(32)

Indicates a random PSK. If the PSK is carried in the request, it is used. Otherwise, the IoT platform generates a random PSK.

Error Codes

HTTP Status Code

Error Code

Error Description

Remarks

200

103028

The license pool resources.

The license resources have been used up.

400

100003

Invalid verify code.

The verification code is invalid.

Recommended handling: Check whether verifyCode carried in the API request is correct. If verifyCode is not carried in the API request, contact IoT platform maintenance personnel.

400

100007

Bad request message.

The request message contains invalid parameters.

Recommended handling: The value of deviceId is not assigned. Set this parameter based on the description of request parameters.

400

100416

The device has already been bounded.

The device has been bound to the IoT platform.

Recommended handling: Check whether the device is registered.

400

100426

The nodeId is duplicated.

The value of nodeId is duplicated.

Recommended handling: Check whether nodeId carried in the API request is correct.

400

50400

The input is invalid.

An input parameter is invalid.

Recommended handling: Check whether parameters carried in the API call request are valid.

401

100025

AppId for auth not exist.

The application ID used for authentication does not exist.

Recommended handling:

  • Check whether the value is assigned to app_key in the header of the request structure.
  • If this API is called using HTTP, contact IoT platform maintenance personnel to check whether the name of appId in the header is app_key or x-app-key.

403

100203

The application is not existed.

The application does not exist.

Recommended handling:

  • Check whether appId carried in the HTTP request header is correct.
  • Check whether appId in the request path (URL) is correct.

403

100217

The application has not been authorized.

The application has not been authorized.

Recommended handling: In scenarios where applications are not authorized, ensure that request parameter appId is null.

403

1010009

app throttle exceed.

The NA calls the API at a frequency that exceeds the flow control threshold (100 calls per minute by default).

Recommended handling: Contact IoT platform maintenance personnel to adjust the flow control threshold or control the API call frequency.

403

1010005

App_key or access_token is invalid.

The access token is invalid.

Recommended handling: Check whether accessToken carried in the API request is correct.

403

600002

The product not existed.

The product does not exist.

Recommended handling: Check whether productId is correct.

500

100001

Internal server error.

An internal server error occurs.

Recommended handling: An internal error occurs on the IoT platform. Contact IoT platform maintenance personnel.

500

100203

The application is not existed.

The authorized application does not exist.

Recommended handling:

  • Check whether appId carried in the HTTP request header is correct.
  • Check whether appId in the request path (URL) is correct.

500

100412

The amount of device has reached the limit.

The number of devices under the current application reaches the upper limit.

Recommended handling: Check whether the number of devices under the current application reaches the upper limit.

500

100441

The amount of nonSecure device has reached the limit.

The number of non-security devices has reached the upper limit.

500

103026

The license is not exist.

The license does not exist.

Recommended handling: An internal license error occurs on the IoT platform. Contact IoT platform maintenance personnel.

500

50252

Internal server error.

An internal server error occurs.

Recommended handling: An internal error occurs on the IoT platform. Contact IoT platform maintenance personnel.