Connecting a Device
API Function
This API is used to connect a device to the IoT platform after the device is bound to the IoT platform for the first time or the device restarts.
API Description
1 | public static boolean login();
|
Class
LoginService
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 connection is successful. The connection is successful only after the LoginService broadcast is received. Before the connection, the API for Configuring Login Parameters (LoginConfig.setConfig) is used to transfer the required connection information.
Example
Call this API to connect a device to the IoT platform.
1 | LoginService.login();
|
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 | public class AgentliteLogin implements MyObserver {
public AgentliteLogin (Observable loginService) {
loginService. registerObserver (this);
}
//Override the update method in the AgentliteLogin.
@Override
public void update(IotaMessage arg0) {
// TODO Auto-generated method stub
System.out.println("LoginManager receives a notification:" + arg0)
int mMsgType = arg0.getMsgType();
switch(mMsgType) {
case 1:
loginResultAction(arg0);
break;
case 2:
logoutResultAction(arg0);
break;
default:
break;
}
}
|
Last Article: (Optional) Configuring the Login Information Encryption Algorithm
Next Article: Disconnecting a Device
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.