• Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us
  • Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us

Client Libraries & SDKs

home/Documentation/Client Libraries & SDKs
  • Device SDK Reference
    • Overview
    • Device Authentication Options
    • Data Flow
    • Public Methods
      • Device Connection
      • Send Telemetry
      • Get Attributes
      • Send acknowledgment
      • Update Twin
    • SDKs (Message version 1.0)
      • DOT NET (C#)
      • Node.js
      • Java
      • Python
      • iOS
      • Android
      • Embedded
      • C language
      • Build Your Own SDK
      • Node-RED
        • IoTConnect Node-red 1.0.9
        • IoTConnect Node-red 1.0.8
      • Node-RED Subflow
        • Single Device
        • Multiple Device
    • SDKs (Message version 2.1)
      • Python
      • DOT NET (C#)
      • C language
        • IoTConnect Generic C SDK
          • Linux Build Instructions
          • Windows Build Instructions
      • Python 1.1
    • Code Samples
      • Node.js
        • TPM 3.1
        • Standard SDK 3.0
        • Standard
        • TPM
        • Standard SDK 3.0.1
        • Standard 2.0
      • Java
        • Standard
        • Standard 2.0
        • Standard 3.0
      • Python
        • Standard 2.0
        • TPM 2.1
        • Standard 3.0.1
        • Standard
        • TPM
          • TPM 3.0.1
        • TPM 3.0
        • Standard 3.0.2
        • Standard 3.0.3
        • Standard 3.0.4
        • Python SDK
      • iOS
        • ios1.0.1
      • C Language
        • nRF9160 DK
        • STM32L4
        • ESP32
        • Standard 3.0
        • Standard 2.0
        • Standard 3.1
      • Android
        • Standard 3.0
        • Standard 2.0.6
        • Standard 2.0.0
      • DOT NET (C#)
        • Standard
        • Standard 2.0
        • Standard 3.0
    • Device Message 1.0
      • D2C (Device to Cloud)
        • IoTConnect SDK
        • Custom SDK
      • C2D (Cloud to Device)
        • IoTConnect SDK
        • Custom SDK
      • Troubleshooting & Response codes
      • Know Your Essentials
    • Device Message 2.1
    • AWS Device Message 2.1
    • SDK Deep-diving
Download PDF

Standard 2.0

Card Image

JAVA SDK

Version 2.0.0

Updated On 01/20

Sample Code for lettest version of SDK

# Date Name Download
1 01/20/2020 Symmetric Key Sample -v2.0.0 Download
2 01/20/2020 Symmetric Key Gateway Sample -v2.0.0 Download
3 01/20/2020 Self Sign Sample -v2.0.0 Download
4 01/20/2020 Self Sign Gateway Sample -v2.0.0 Download
5 01/20/2020 CA Sign Sample -v2.0.0 Download
6 01/20/2020 CA Sign Gateway Sample -v2.0.0 Download

How to run the JAVA sample code?

Prerequisite tools

  • Java 8 (or above )
  • Eclipse IDE

Installation

  • Extract the “iotconnect-sdk-java-v2.0.0.zip” (You can download SDK file from here)
  • Open Eclipse and create a new JAVA project.
  • Create lib folder inside the newly created project.
  • Put JAR(You can get JAR file from iotconnect-sdk-java-v2.0.0.zip) file inside lib
  • Put config.properties file inside the project(You can get properties file from iotconnect-sdk-java-v2.0.0.zip).
  • Configure JAR file to the project.Right-click on the project and click on Build Path and then click on Configure Build Path.
  • Click on Java Build Path and then go to Libraries Tab and then click on Add JARs
  • Now Select sdk-2.0.jar from lib folder and then click on OK button.
  • Create new Java Class file inside src folder(You can get sample file(Sample.java) code from iotconnect-sdk-java-v2.0.0.zip).

Public Method and Implementations
Prerequisite input data

  • Get your Environment(ENV) Details
  • Get your CPID
uniqueId = <<uniqueId>>;    //It's your device uniqueId
	cpid = <<CPID>>;            //
	You can get it from portal with admin user
	env = <<env>>;              
	

Create a new to implement callback interface SDKCallback. You can use “Sample.java” file as a reference that is available in the extracted zip file.

//Callback class
	class CBImplementor implements SDKCallback, TwinCallback {
		//Implement a method to receive the command from Cloud 
		@Override
		public void sdkCallbackMethod(CloudResponse 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());
			}      
		}
		@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

 
	//Create iotconnect sdk instance
	IoTConnectSDK ioTConnectSDK = new IoTConnectSDKImpl(cpId, uniqueId, env, 
	callerClassObject, callerClassObject);
	

To send the data from Device To Cloud(D2C)

//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>>'}]")
	

SDK Configuration

  • “config.properties” is required to give additional information regarding certificates
  • You can find “config.properties” in sample folder i.e. “sample/config.properties”, if SDK doesn’t find this file then it will give “Config file not found” error. Means you are missing this file at root location in case you are integrating with firmware
  • Standard file format for the config.properties file is as below:
 
	filePath= <filepath>
	caFile= <filename>/ca.cert.pem
	clientCrtFile= <filename>/cert..pem
	clientKeyFile= <filename>/key.pem
	clientKeyPassword= <password>
	
  • If your device is using certificate base authentication then you have to provide bellow information else you can keep it blank. Make sure each file path are valid and accessible:
    • caFile : Root server CA certificate file path
    • clientCrtFile : Device certificate file path
    • clientKeyFile : Device key file path
    • clientKeyPassword : Key password

NOTE: It will cause an issue if property name got changed so please make sure none of the property get renamed

To update the Twin Property

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

Sample code SDK integration

//Import iotconnect package
	package sdk;
	
	//Import required classes	
	import sdk.dao.d2c.CloudResponse;
	import sdk.service.IoTConnectSDK;
	import sdk.service.IoTConnectSDKImpl;
	import sdk.service.SDKCallback;
	
	//Sample Class
	public class demo {
		public static void main(String[] args) throws Exception {
			CBImplementor cb = new CBImplementor();
			String env = "<<env>>";  //Replace your environment here
			String uniqueId = "<<uniqueId>>";  //Replace device uniqueid here
			String cpId = "<<cpid>>";  //Replace CPID here
	
			IoTConnectSDK ioTConnectSDK = new IoTConnectSDKImpl(cpId, uniqueId, env, cb, cb);
			ioTConnectSDK.sendData("[{'data':{'humidity':'1211'},
	'time':'2020-02-28T10:49:37.658Z','uniqueId':'<<uniqueId>>'}]"); 
	// Replace device uniqueid here
		}
	}
	
	//Callback class
	class CBImplementor implements SDKCallback, TwinCallback {
		@Override
		public void sdkCallbackMethod(CloudResponse 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());
					 }
		}
		   @Override
		public void twinCallBackMethod(Map<String, String> arg0) {
			if(arg0.size() > 0){
				System.out.println(arg0.toString());
				System.out.println("Twin Property Updated");
			}
		}
	}
	

Troubleshooting

Device not found
Message: ERROR sdk.service.IoTConnectSDKImpl – Device not found
Reason: Device not registered on IoTConnect cloud
Solution:
– It should be valid and respective to the entered CPID and ENV
– The device should be registered with entered uniqueId on IoTConnect cloud respective to the selected CPID and ENV
– If your device name is wrong then you need to stop the script and run again after uniqueId correction.

CPID not found
Message: ERROR sdk.service.IoTConnectSDKImpl – Unidentified Error
Reason: Wrong CPID entered
Solution:
– CPID should be valid. You can take it from here (Reference link to get cpid)
– Check the combination of CPID and ENV (IoTConnect platform environment)

Device not registered
Message: ERROR sdk.service.IoTConnectSDKImpl – Device not registered
Reason: Device not registered on cloud
Solution:
– If your uniqueId is right and till you getting the above error then verify below process
– It should be registered on IoTConnect Platform respective to the selected CPID and ENV
– Its status should be “Acquired” (registered on the cloud)

Powered by Softweb – An Avnet Company.

Copyright ©2022 Avnet, Inc. All rights reserved.

Human Rights Privacy Terms of Use