IoTIoT

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Anti-DDoS Service
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain Service
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
DevCloud
ProjectMan
CodeHub
CloudRelease
CloudPipeline
CloudBuild
CloudDeploy
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
IoT
IoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Updated at: Feb 24, 2022 GMT+08:00

Binding a Device

API Function

A device must be bound to the IoT platform before accessing the IoT platform for the first time. The upper-layer application calls this API to transfer the device serial number, MAC address, or other device information to bind a device to the IoT platform.

Before binding a device, developers must call the Binding Configuration API to set the IP address and port number of the IoCM server to be bound. The default port number is 8943 for the AgentLite.

NOTE:

Before a directly connected device accesses the IoT platform for the first time, developers must register the device with the IoT platform and then initiate a binding request on the device. If the device is not registered with the IoT platform, the binding fails. The AgentLite waits for a while and tries again.

API Description

1
public static boolean bind(String verifyCode, IotaDeviceInfo deviceInfo);

Class

BindService

Parameter Description

Parameter

Mandatory or Optional

Type

Description

verifyCode

Mandatory

String

Specifies a device binding verification code.

If the device is registered on the SP portal, set verifyCode to the preSecret used during device registration.

deviceInfo

Mandatory

IotaDeviceInfo

Specifies information about the device.

Return Value

Return Value

Description

true

Success

false

Failure

NOTE:
  • 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 binding is successful. The binding is successful only after the BindService.TOPIC_BINDDEVICE_RSP broadcast is received.
  • If the binding fails, the AgentLite automatically binds the device after 30 seconds. If the retry fails for five consecutive times (the total number of attempts is six), a message is returned indicating that the binding fails and the binding stops. If developers want to re-initiate the binding, restart the device.

Output

Broadcast Name

Broadcast Parameter

Member

Description

TOPIC_BINDDEVICE_RSP

IotaMessage object

(Obtained by using intent.getSerializableExtra(BindService.BIND_BROADCAST_MSG_IE_IOTAMSG))

BIND_IE_RESULT

Specifies the binding result.

BIND_IE_DEVICEID

Specifies the logical device ID assigned by the IoT platform.

BIND_IE_DEVICESECRET

Specifies the authentication secret for a device to access the IoT platform.

BIND_IE_APPID

Identifies an application.

BIND_IE_HA_ADDR

Specifies the IP address of the HA server.

BIND_IE_LVS_ADDR

Specifies the IP address of the LVS server.

Example

Call this API to bind a device.

1
BindService.bind(new IotaDeviceInfo("nodeId", "manufacturerId", " Gateway", "model", "protocolType")); 

Receive a device binding response.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
//After a device is bound, the AgentLite will return the parameters shown in the following output. Developers must store these parameters and configure these parameters on the device before connecting the device to the IoT platform.
BroadcastReceiver mBindRsp; 
mBindRsp = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
    //Do Something 
    IotaMessage iotaMsg = (IotaMessage)intent.getSerializableExtra(BindService.BIND_BROADCAST_MSG_IE_IOTAMSG); 
    int result = iotaMsg.getUint(BindService.BIND_IE_RESULT, 0); 
    String deviceId = iotaMsg.getString(BindService.BIND_IE_DEVICEID); 
    String Secret = iotaMsg.getString(BindService.BIND_IE_DEVICESECRET); 
    String Appid = iotaMsg.getString(BindService.BIND_IE_APPID); 
    String haAddr = iotaMsg.getString(BindService.BIND_IE_HA_ADDR); 
    String lvsAddr = iotaMsg.getString(BindService.BIND_IE_LVS_ADDR); 
    return;  
    } 
}; 
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); 
IntentFilter filterBind = new IntentFilter(BindService.TOPIC_BINDDEVICE_RSP); 
mLocalBroadcastManager.registerReceiver(mBindRsp, filterBind);

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel