Skip to content

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.

Hint

In the IoT context, assets are referred to as entity and aspects as propertyset.
Placeholders in the following samples are indicated by angluar 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.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// 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
}

Any questions left?

Ask the community


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