Skip to content

IoT Time Series Client for Java

Introduction

The IoT TimeSeries Java client allows you to interact with time series data related to assets.

Refer to IoT Time Series for more information about the service.

Hint

In the IoT context, assets are referred to as entity and aspects as propertyset.

Time Series Operations

Client Name: TimeSeriesClient

Read Time Series Data

This operation invokes the IoT Time Series API to:

  • Read time series data for a single aspect of an asset.
  • 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
 8
 9
10
11
12
13
//Construct TimeseriesClient object as shown above
List<TimeseriesData> timeseriesDataList = null;

try {
  String from = "2018-01-24T05:03:41.363Z";
  String to = "2018-01-24T05:04:41.363Z";
  Integer limit = 100;
  String select = null;

  timeseriesDataList = timeseriesClient.getTimeseries(entity, propertySetName, from, to, limit, select);
} catch (MindsphereException e) {
  // Exception handling
}

Read Latest Time Series Data

Read the latest value of time series data for a single aspect of an asset.

 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();

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

Write Time Series Data

Write time series data for a single aspect of an asset. This overwrites existing time series data.

Note

The maximum size of a write payload is 1 MB.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Construct TimeseriesClient object as shown above

// Creating list of Timeseries data objects to be added
List<Timeseries> timeSeriesList = new ArrayList<>();

// Create a Timeseries object
Timeseries timeseriesObject = new Timeseries();
timeseriesObject.setTime(Instant.now().toString());

// Create a map to add timeseries values to variables of the entity
Map<String, Object> dataMap = timeseriesDataOnject1.getFields();
dataMap.put("FRWheel", 99);
dataMap.put("FLWheel", 98);

// Add the timeseries object to timeseries list
timeSeriesList.add(timeseriesObject);

try {
  timeseriesClient.putTimeSeries(entity, propertySetName, timeSeriesList);
} catch (MindsphereException e) {
// Exception handling
}

Delete Time Series

Delete time series data from an aspect of an asset within a given time range. It also deletes data for all variables within an aspect.

Note

Only the data for up to 6 months can be deleted at once.

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

try {
  timeseriesClient.deleteTimeSeries(entity, propertySetName, from, to);
} 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.