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.
Further implementation of the IOT TimeSeries SDK library has been shown in a sample project that you can download and test in local or on Insights Hub application. Please refer to this repository: industrial-iot-java-sdk-examples
Hint
In the IoT context, assets are referred to as entity and aspects as propertyset.
Placeholders in the following samples are indicated by angular brackets < >
.
Time Series Operations¶
Client Name: TimeSeriesOperationsClient
Create or update time series data for multiple unique asset-aspect (entity-property set) combinations¶
- Create or update time series data for multiple unique combinations of assets (entities) and aspects (property sets). In case of an update of data at an already existing time, all properties at that time will be replaced by the ones provided in the request. All asset-aspect (entity-property set) combinations need to belong to the same tenant.
Request body limitations:
- A maximum of 5 asset-aspect (entity-property set) combinations can be provided
- The request body size must be equal or less than 100 kb
- A maximum of 100 time series data items can be provided overall
// Construct the PackageProvisioningClient object
TimeSeriesOperationsClient ts = TimeSeriesOperationsClient.builder().
restClientConfig(config).build();
CreateOrUpdateTimeseriesRequest createOrUpdateTimeseriesRequest = new CreateOrUpdateTimeseriesRequest();
TimeSeries timeseries = new TimeSeries();
TimeSeriesItem timeSeriesItem = new TimeSeriesItem();
List<TimeSeriesItem> liSeriesItems = new ArrayList<TimeSeriesItem>();
TimeSeriesItem timeSeriesItem1 = new TimeSeriesItem();
timeSeriesItem1.setEntityId("5908ae5c5e4f4e18b0be58cd21ee675f");
timeSeriesItem1.setPropertySetName("test_2020_11_11");
TimeSeriesDataItem timeSeriesDataItem1 = new TimeSeriesDataItem();
Map<String, Object> dataMap1 = timeSeriesDataItem1.getFields();
dataMap1.put("test", 80);
timeSeriesDataItem1.setTime("2020-11-11T02:52:00Z");
List<TimeSeriesDataItem> lisDataItems1 = new ArrayList<TimeSeriesDataItem>();
lisDataItems1.add(timeSeriesDataItem1);
timeSeriesItem1.setData(lisDataItems1);
liSeriesItems.add(timeSeriesItem1);
timeseries.setTimeseries(liSeriesItems);
createOrUpdateTimeseriesRequest.setTimeseries(timeseries);
try {
MultiStatusError multiStatusError = ts.createOrUpdateTimeseries(createOrUpdateTimeseriesRequest);
} catch (MindsphereException e) {
// Exception handling
}
Create or update time series data¶
- Create or update time series data for one combination of an asset (entity) and an(a) aspect (property set). In case of an update of data at an already existing time, all properties at that time will be replaced by the ones provided in the request.
CreateOrUpdateTimeseriesDataRequest requestObject = new CreateOrUpdateTimeseriesDataRequest();
requestObject.setEntityId("5908ae5c5e4f4e18b0be58cd21ee675f");
requestObject.setPropertySetName("test_2020_11_11");
TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem();
timeSeriesDataItem.setTime("2020-11-06T10:00:00Z");
Map<String, Object> dataMap = timeSeriesDataItem.getFields();
dataMap.put("test", 99);
// dataMap.put("RLwheel", 98);
List<TimeSeriesDataItem> lisDataItems = new ArrayList<TimeSeriesDataItem>();
lisDataItems.add(timeSeriesDataItem);
requestObject.setTimeseries(lisDataItems);
try {
ts.createOrUpdateTimeseriesData(requestObject);
} catch (MindsphereException e) {
// Exception handling
}
Delete time series data¶
- Delete time series data for one combination of an asset (entity) and an(a) aspect (property set). All property values within the given time range are deleted.
DeleteUpdatedTimeseriesRequest requestObject = new DeleteUpdatedTimeseriesRequest();
requestObject.setEntityId("5908ae5c5e4f4e18b0be58cd21ee675f");
requestObject.setPropertySetName("test_2020_11_11");
requestObject.setFrom("2020-11-12T15:10:00Z");
requestObject.setTo("2019-11-13T16:18:00Z");
try {
ts.deleteTimeseries(requestObject);
} catch (MindsphereException e) {
// Exception handling
}
Retrieve time series data¶
- Retrieve time series data for one combination of an asset (entity) and an(a) aspect (property set). The maximum number of time series data items returned per request is defined by parameter <i>limit</i>. In case more time series data items are present in the requested time range, only a subset of data items will be returned and a header <i>link</i> is added to the response. The header value contains the request URL to fetch the next set of time series data items, by increasing the parameter accordingly. Returns the latest record if no range is provided.
RetrieveTimeseriesRequest requestObject = new RetrieveTimeseriesRequest();
requestObject.setEntityId("5908ae5c5e4f4e18b0be58cd21ee675f");
requestObject.setPropertySetName("test_2020_11_11");
try {
List<TimeSeriesDataItem> response = ts.retrieveTimeseries(requestObject);
} catch (MindsphereException e) {
// Exception handling
}
Last update: February 23, 2024
Except where otherwise noted, content on this site is licensed under the Development License Agreement.