IoT Time Series Client for Node.js¶
Introduction¶
The IoT Time Series Node.js 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-node-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 angle brackets < >
.
Time Series Operations¶
Client Name: TimeSeriesClient
Read Time Series Data¶
This operation invokes the IoT Time Series API for the following use cases:
- 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.
// Require AppCredentials and ClientConfig from mindsphere-sdk-node-core module
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;
// Require TimeSeriesClient from timeseries-sdk module
const TimeSeriesClient = require('timeseries-sdk').TimeSeriesClient;
// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();
// Construct the TimeseriesAggregateClient object
let time_series_client = new TimeSeriesClient(config, credentials);
let timeseries_data;
try {
const request_object = {
entity: <entity_id>,
propertysetname: <property_set>,
from: <from_date>,
to: <to_date>,
limit: <limit>,
select: <select>
};
timeseries_data = await time_series_client.getTimeseries(request_object);
} catch (ex) {
// Exception handling
}
Read Latest Time Series Data¶
Read the latest value of time series data for a single aspect of an asset.
// Construct the TimeseriesAggregateClient object as shown above
let timeseries_data;
try {
const request_object = {
entity: <entity_id>,
propertysetname: <property_set>
};
timeseries_data = await time_series_client.getTimeseries(request_object);
} catch (ex) {
// 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.
// Construct the TimeseriesAggregateClient object as shown above
let timeseries_data = [
{
FRWheel: 5.0,
FLWheel: 78.0,
RLWheel: 6.0,
RRWheel: 10.0,
_time: '2018-01-24T05:04:41.363Z'
}
];
try {
const request_object = {
entity: <entity_id>,
propertysetname: <property_set>,
timeseries: <timeseries_data>
};
await time_series_client.putTimeseries(request_object);
} catch (ex) {
// Exception handling
}
Delete Time Series Data¶
Delete time series data from an aspect of an asset within a given time range. This also deletes data for all variables within the aspect.
Note
Only data of up to 6 months can be deleted at once.
// Construct the TimeseriesAggregateClient object as shown above
try {
const request_object = {
entity: <entity_id>,
propertysetname: <property_set>,
from: <from_date>,
to: <to_date>
};
await time_series_client.deleteTimeseries(request_object);
} catch (ex) {
// Exception handling
}