
# Softweb Solutions Inc
## IOT Connect SDK : Software Development Kit 1.0.0

**Prerequisite tools:**

1.	Java 8 (or above )
2. 	Eclipse IDE

**Installation :** 

- Extract the "iotconnect-sdk-java-v2.0.0.zip"
	
**Usage :**

Follow the steps given below to import our SDK as a library
 - Open Eclipse IDE and Create/Open Project
 - Add **jar** file into lib folder (Get **jar** file from “iotconnect-sdk-java-v2.0.0.zip”)

Prerequisite input data *
```java
uniqueId = <<uniqueId>>;	//It's your device uniqueId
cpid = <<CPID>>;		//You can get it from portal with admin user
env = <<env>>;			//DEV, QA, POC, PROD(Default)
```

Create a new to implement callback interface **SDKCallback**. You can use **"Sample.java"** file as reference which is available in extracted zip file.
```java
//Callback class
class CBImplementor implements SDKCallback, TwinCallback, IotHubEventCallback {
    @Override
    public void sdkCallbackMethod(CloudResponse cloudResponse) {
        // TODO : sdkCallbackMethod
    }

    @Override
    public void execute(IotHubStatusCode responseStatus, Object callbackContext) {
        // TODO : IotHubEventCallback
    }

    @Override
    public void twinCallBackMethod(Map<String, String> arg0) {
        if(arg0.size() > 0){
            System.out.println(arg0.toString());
            System.out.println("Twin Property Updated");
        }
    }
}
```

Create SDK instance using prerequisite date and connect to IoTConnect
```java
IoTConnectSDK ioTConnectSDK = new IoTConnectSDKImpl(cpId, uniqueId, env, callerClassObject, callerClassObject);
```

To send the data from Device To Cloud(D2C)
```java
 //Date time will be in ISO 8601 format. Example: YYYY-MM-DDTHH:MM:SS.sssZ
 ioTConnectSDK.sendData("[{'data':{'humidity':'1211'},'time':'2020-02-28T10:49:37.658Z','uniqueId':'<<uniqueId>>'}]");)
```

To configure the secure SSL/x509 connection follow below step for CA or CA Selfsiged certificate
	- Open file : config.properties
    - Set the certificate path like as below:

```java
	filePath= <<filepath>>
	caFile= <<filename>>/ca.cert.pem
	clientCrtFile= <<filename>>/cert..pem
	clientKeyFile= <<filename>>/key.pem
	clientKeyPassword= <<password>>
```

To update the Twin Property

```java
    Map<String,String> twinPropertyMap = new HashMap<>();
    twinPropertyMap.put("humidity", "100");
			
    ioTConnectSDK.updateTwin(twinPropertyMap);
```