Sample Code for lettest version of SDK
# | Date | Name | Download |
---|---|---|---|
1 | 01/09/2018 | Symmetric Key Sample Android v2.0.0 | Download |
How to run an Android sample code?
Prerequisite tools:
- Java 8 (or above)
- Android SDK
- Android Studio
Installation:
1. Please verify jcenter in your root build.gradle at the end of repositories:
allprojects { repositories { ... jcenter() } }
2. Add the dependency
dependencies { implementation 'com.iotconnectsdk:iotconnectpoc:2.0.0' }
Usage:
Add library
Prerequisite input data
uniqueId = <<uniqueId>>; cpid = <<CPID>>; env = <<env>>;
public class JavaSDKClient implements IotSDKCallback { }
To get the device information and connect to the device
IoTConnectSDK ioTConnectSDK = new IoTConnectSDK(context,cpid,uniqueId, callerClassObject,env);
Implement methods to receive the command from Cloud to Device(C2D)
public void onReceiveMsg( HubToSdkDataBean cloudResponse) { if(cloudResponse!=null) { System.out.println("ACK : " + cloudResponse.getAck()); System.out.println("ACK ID : " + cloudResponse.getAckid()); System.out.println("Command : " + cloudResponse.getCommand()); System.out.println("UniqueId : " + cloudResponse.getUniqueid()); System.out.println("Value : " + cloudResponse.getValue()); } }
Get attributesList
public void attributeData(final List<SyncServiceResponse.DBeanXX.AttBean> attributesBeanList) { }
Get connection status
public void onConnectionStateChange(boolean isConnected) { }
To send the data from Device To Cloud(D2C)
ioTConnectSDK.SendData(sendTeledata)
Disconnect iotConnect on Activtiy onDestroy
@Override protected void onDestroy() { super.onDestroy(); if(iotConnect!=null) { ioTConnectSDK.disconnectSDK(); } }