Skip to content

IoT Time Series Client for Java

Introduction

The IoT Time Series Java client allows you to interact with time series data related to entity instances.

See IoT Time Series for more information about the service.

Time series operations

Client Name: TimeseriesClient

Read latest time series

Read the latest value of time series data for a single entity and property set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
    // Construct the TimeseriesClient object
    TimeseriesClient timeseriesClient = TimeseriesClient.builder()
                                            .mindsphereCredentials(credentials)
                                            .restClientConfig(config)
                                            .build();

    TimeseriesData timeseriesData = null;
    try {
        timeseriesData = timeseriesClient.getLatestTimeseries(entity, propertySetName);
    } catch (MindsphereException e) {
        // Exception handling
    }

Read time series

This operation invokes the IoT Time Series API to:

  • Read time series data for a single entity and property set.
  • Return data for a specified time range.
  • Return the latest value if no range is provided.
  • Return time series data for selected fields and limit.
1
2
3
4
5
6
7
  //Construct TimeseriesClient object as shown above
  List<TimeseriesData> timeseriesDataList = null;
  try {
    timeseriesDataList = timeseriesClient.getTimeseries(entity, propertySetName, from, to, limit, select);
  } catch (MindsphereException e) {
    // Exception handling
  }

Write time series

Write the time series for a single entity and property set. The existing time series data will be overwritten.

Note

The maximum size of a write payload is 1 megabyte.

1
2
3
4
5
6
7
8
  //Construct TimeseriesClient object as shown above

  boolean success = false;
  try {
    success = timeseriesClient.putTimeSeries(entity, propertySetName, timeSeriesList, sync);
  } catch (MindsphereException e) {
  // Exception handling
  }

Import time series

Import or update time series for a single entity and property set. The existing time series data is overwritten.

1
2
3
4
5
6
7
8
    //Construct TimeseriesClient object as shown above

    boolean success = false;
    try {
      success = timeseriesClient.importTimeseries(entity, propertySetName, timeseriesFile, sync);
    } catch (MindsphereException e) {
      // Exception handling
    }

Delete time series

Delete time series entity and property set within a given time range. It also deletes data for all properties within a property set.

Note

At a time, only the data for 6 months can be deleted.

1
2
3
4
5
6
7
8
    //Construct TimeseriesClient object as shown above

    boolean success = false;
    try {
      success = timeseriesClient.deleteTimeSeries(entity, propertySetName, from, to, sync);
    } catch (MindsphereException e) {
      // Exception handling
    }

Page Iterators

The page iterator for the IoT Time Series API client, TimeseriesPageIterator can be used to get a specific page, the next page or the previous page of data.

The page iterators currently support the following operations:

  • getPage(Integer pageNumber);
  • next();
  • previous();

The page iterator instantiation requires an IoT Time Series API client, an entity, a property set name, a date range (from and to dates) and a page size. If the page size is not provided, it defaults to 2000.

Code sample for the IoT Time Series page iterator instantiation and usage:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
try {
    //Create the timeseries client
    TimeseriesClient timeseriesClient =  TimeseriesClient.builder()
                .mindsphereCredentials(credentials)
                .restClientConfig(config)
                .build();
        // Create the timeseries page iterator
  TimeseriesPageIterator timeseriesPageIterator =
      new TimeseriesPageIterator(timeseriesClient, entityId, propertySetName, fromDateString, toDateString, pageSize);

  List<TimeseriesData> timseriesDataList = timeseriesPageIterator.getPage(10);
} catch (MindsphereException e) {
  // Exception handling
}

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.