MindConnect-NodeJS - CLI - Uploading Data to MindSphere

Introduction

The MindConnect APIs provide the agents with the possibility to

  • ingest timeseries data (mc upload-timeseries)
  • create events in the Mindsphere (mc create-event)
  • upload files to the the MindSphere (mc upload-file)

All these commands use the agent credentials. Take a look at Agent Management part of the documentation for instructions how to acquire them.

Ingesting Time Series Data via MindConnect (mc upload-timeseries)

This commands are provided for testing/working with the MindConnect (Agent) interfaces. IF you want to use this CLI to import historical data please take a look to the uploading historical data part of the documentation.

This command offers to the user a way to import the .csv files through MindConnect (Agent) API.

mc upload-timeseries --help

Usage: upload-timeseries|ts [options]

parse .csv file with timeseriesdata and upload the timeseries data to mindsphere

Options:
  -c, --config <agentconfig>       config file with agent configuration (default: "agentconfig.json")
  -r, --cert [privatekey]          required for agents with RSA_3072 profile. create with: openssl genrsa -out private.key 3072
  -f, --file <timeseriesdata.csv>  csv file containing the timeseries data to upload to mindsphere
  -s, --size <size>                max records per http post (default: 200)
  -n, --no-validation              switch validation off (only if you are sure that the timeseries upload works)
  -y, --retry <number>             retry attempts before giving up (default: 3)
  -v, --verbose                    verbose output
  -h, --help                       output usage information

  Examples:

    mc ts -f timeseries.csv        upload timeseries from the csv file to mindsphere
    mc upload-timeseries --file timeseries.csv  --size 100  use http post size of 100 records

  Data Format: (use your own data point ids from mindsphere)

  timestamp, dataPointId, qualityCode, value
  2019-05-16T14:50:53.048Z, DP-Temperature ,0, 20.34
  2019-05-16T14:50:54.048Z, DP-Humidity, 0, 70
  2019-05-16T14:50:55.048Z, DP-Pressure, 0, 1012.3

  Make sure that the timestamp is in ISO format. The headers and the casing (timestamp, dataPointId) are important.
  The values must correspond with data types configured in mindsphere (in example: DP-Humidity must be an integer)

  Important:

    You have to configure the data source and data mappings in mindsphere asset manager before you can upload the data
    See also: https://documentation.mindsphere.io/resources/html/asset-manager/en-US/116404525451.html

Example

The timeseries data for the upload must match your DataSourceConfiguration in the Mindsphere. For example: if you have the data source configuration from the development example the csv file should look like in the documentation below.

Make sure that the timestamp is in ISO format. The headers and the casing (timestamp, dataPointId) are important. The values must correspond with data types configured in mindsphere (in example: DP-Humidity must be an integer)

timestamp, dataPointId, qualityCode, value
2019-05-16T15:58:37.626Z, DP-Temperature ,0, 20.34
2019-05-16T15:58:38.626Z, DP-Humidity, 0, 70
2019-05-16T15:58:39.626Z, DP-Pressure, 0, 1012.3

Running the command

mc upload-timeseries --file timeseries.csv --size 100 --config agentconfig.json

will upload the data to MindConnect API in batches of 100 messages.

Creating events (mc create-event)

This command can also be used with service credentials instead.

Usage: create-event|ce [options]

create an event in the mindsphere (optional: passkey) *

Options:
  -c, --config <agentconfig>     config file with agent configuration (default: "agentconfig.json")
  -r, --cert [privatekey]        required for agents with RSA_3072 profile. create with: openssl genrsa -out private.key 3072
  -i, --assetid <assetid>        asset id from the mindsphere  (default: send event to the agent)
  -y, --sourceType <sourceType>  Source Type (default: "MindConnect-Agent")
  -S, --sourceId <sourceId>      Source Id (default: "md1ru58c")
  -O, --source <source>          Source (default: "MindConnect-NodeJs CLI")
  -V, --severity <severity>      Severity (20:Error, 30:Warning , 40:information) (default: 20)
  -d, --desc <description>       Event description (default: "CLI created event")
  -t, --timestamp <timestamp>    Timestamp (default: "2019-05-16T16:19:56.373Z")
  -y, --retry <number>           retry attempts before giving up (default: 3)
  -p, --passkey <passkey>        passkey (optional, file upload uses service credentials *)
  -v, --verbose                  verbose output
  -h, --help                     output usage information

  Examples:

    mc create-event                           create error event with default values and current timestamp
    mc ce --desc Warning! --severity 30       create warning with description warning
    mc ce --desc "custom event" --i 123....4  create error event for asset with id 123....4

Example

mc create-event --desc "This is a custom event" --severity 40

This will create event in the agent asset. You can add the –assetid {assetid} if you want to send the event to a different asset.

Severity levels:

- 20: Error - 30: Warning - 40: Information

Uploading files (mc upload-file)

This command can also be used with service credentials instead.

The upload-file command can upload the files to mindsphere. If the files are bigger then 8MB you can use –chunked option which will switch the uploading of data to the multipart upload instead. The mime type of the file is automatically determined but it can be overriden in the mindsphere.

Usage: upload-file|uf [options]

upload the file to the mindsphere file service (optional: passkey) *

Options:
  -c, --config <agentconfig>  config file with agent configuration (default: "agentconfig.json")
  -r, --cert [privatekey]     required for agents with RSA_3072 profile. create with: openssl genrsa -out private.key 3072
  -f, --file <fileToUpload>   file to upload to the file service
  -h, --filepath <filepath>   file path in the mindsphere
  -l, --parallel <number>     parallel chunk uploads (default: 3)
  -i, --assetid [assetid]     asset id from the mindsphere  (default: upload to the agent)
  -m, --mime [mime-type]      mime type of the file (default: automatic recognition)
  -d, --desc [description]    description
  -k, --chunked               Use chunked upload
  -y, --retry <number>        retry attempts before giving up (default: 3)
  -p, --passkey <passkey>     passkey (optional, file upload uses service credentials *)
  -v, --verbose               verbose output
  -h, --help                  output usage information

  Examples:

    mc uf -f CHANGELOG.md        upload file CHANGELOG.md to the agent
    mc upload-file --file  CHANGELOG.md  --assetid 5...f --mime text/plain    upload file to a specified asset with custom mime type
    mc upload-file --file  CHANGELOG.md  --chunked     upload file using experimental chunked upload

Example

The following command will upload the file to the MindSphere using multipart upload and 5 parallel threads.

mc upload-file --file simulationdata.zip --chunked --parallel 5

The command returns the md5 hash of the uploaded file.

The content of the community tools and libraries documentation pages is licensed under the MIT License.
Siemens API Notice applies.
Back to top