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.
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 |
Specifies information about the device. |
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 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);
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot