The Java SDK for HTTP is maven-based. If you use Maven 3, you just need to add the dependency upon the Java SDK for HTTP to the main pom.xml file of your project, saving the efforts to download and build from source code.
For instructions on downloading and installing Maven 3, see here.
Select one of the following ways to install the Java SDK for HTTP:
-
If your project is maven-based, add the dependency on the Java SDK to the main pom.xml of your project.
-
Download the source code and build on your machine.
This is the recommended method to use EnOS Device SDKs in your project. Your project has to be a Maven project and you have installed Maven on your machine.
-
Go to http://search.maven.org. Search for com.envisioniot enos-http and find the version number for the SDK that you want to use.
-
In your main pom.xml file, add the dependency on the SDK of your desired version by inserting the following code snippet:
<dependency> <groupId>com.envisioniot</groupId> <artifactId>enos-http</artifactId> <version>0.1.8</version> <!--This is latest current version number when this document is being written. Yours may vary.--> </dependency>
-
Download the source code of EnOS Device SDK for Java from the master branch of the GitHub repository: https://github.com/EnvisionIot/enos-device-sdk-java
If you use the command-line interface, the command for download is as follows:
git clone https://github.com/EnvisionIot/enos-device-sdk-java.git
-
Build the SDK from source code using the following command in your command-line interface:
cd enos-device-sdk-java/enos-http-sdk mvn install
The compiled JAR file with all dependencies bundled can then be found in the following file:
{Device SDK for Java root}/enos-http-sdk/target/enos-http-{version}.jar
If you want to use the device SDK in your own project, include this JAR file and any JAR files that the device SDK depends on in your project.
For the list of features supported by this SDK and the availability of EnOS device connectivity and management features in all SDKs we provide, see EnOS Device SDK.
-
Create an HTTP connection and specify the connection parameters.
// Create a static-authentication secret triple, which includes ProductKey, DeviceKey and DeviceSecret // The ProductKey, DeviceKey and DeviceSecrect can be obtained in Device Details page in EnOS Console StaticDeviceCredential credential = new StaticDeviceCredential( PRODUCT_KEY, DEVICE_KEY, DEVICE_SECRET); // Create an HTTP connection SessionConfiguration configuration = SessionConfiguration.builder().lifetime(30_000).build(); // BROKER_URL is the URL of EnOS HTTP Broker for Devices, which can be obtained in the Environment Information page in EnOS Console HttpConnection connection = new HttpConnection.Builder(BROKER_URL, credential) .sessionConfiguration(configuration) .build();
-
Report measurement points via the HTTP connection.
// Build a request to post a measurement point // MeasurePoint1 is a measurement point defined in EnOS console > Model. MeasurepointPostRequest request = MeasurepointPostRequest.builder() .addMeasurePoint("MeasurePoint1", 100) .build(); // Publish the request synchronously try { MeasurepointPostResponse response = connection.publish(request, null); } catch (EnvisionException | IOException e) { e.printStackTrace(); }
-
To learn more about EnOS IoT Hub, see EnOS IoT Hub Documentation.
-
To learn more about how to develop your device for EnOS IoT Hub, see EnOS Device Development Guide (Java).
-
2020/01/15 (Initial Release): Reporting measurement points (including file-type points)
-
2020/05/07 (0.1.4): Support deleting and downloading files
-
2020/05/14 (0.1.5): Fix NPE while uploading measurepoints
-
2020/07/22 (0.1.6): Fix security vulnerabilities
-
2020/08/17 (0.1.7): Support file upload/download via EnOS LARK and support OTA
-
2020/12/09 (0.1.8): Add some log information
-
2021/06/28 (0.2.0): Support ssl for http auth and file download by range
-
2021/12/21 (0.2.1): Support poll command.