Skip to content

Latest commit

 

History

History
163 lines (129 loc) · 5.61 KB

README.adoc

File metadata and controls

163 lines (129 loc) · 5.61 KB

Using EnOS Device SDK For Java (HTTP)

Installation

Prerequisites

Installing Java JDK SE

Java SE 8 is required to use the SDK and run the samples.

Optional: Installing Maven

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.

Installing EnOS Device SDK for Java (HTTP)

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.

Adding the Maven Dependency to Your Project

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.

  1. 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.

  2. 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>

Building From the Source Code

  1. 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
  2. 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.

Feature List

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.

Quick Start

  1. 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();
  2. 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();
    }

API Reference

Under development

Release Notes

  • 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.