Example - Upload and View Values

This chapter describes how WinCC OA values are uploaded to Insights Hub. Note that Insights Hub must be successfully configured.

Upload Values via a CTRL Script

An advantage of the library is an automatic handling of the redundancy in WinCC OA. Values are only uploaded by the WinCC OA Server when it is the active server (in the split mode the computer on which the active Event-Manager is running). Furthermore, it allows you to prepare values for the upload and then upload them.

Note that you include the Insights Hub library: #uses "classes/mindSphere/MindSphereAsset"

  • #uses "classes/mindSphere/MindSphereAsset"
    main(mapping event)
    {
      MindSphereAsset asset = MindSphereAsset("NameOfMindSphereAsset");
    }

If you want to use shared_ptr, you can instance a MindSphereAsset also as follows:

  • #uses "classes/mindSphere/MindSphereAsset"
    main(mapping event)
    {
      shared_ptr<MindSphereAsset> asset = new MindSphereAsset("NameOfMindSphereAsset");
    }

If you use the name of an inexistent asset when instancing an object, the error code -1 is returned by the calling functions.

  • In the next step, select values that are uploaded to Insights Hub. Select the MindSphereDatapoints to which the values are uploaded.
  • string dp1 = "NameOfTheMindSphereDatapoint1";
    string dp2 = "NameOfTheMindSphereDatapoint2";
    dyn_int values1 = makeDynInt(1, 2, 3);
    dyn_int values2 = makeDynInt(4, 5, 6);
    time now = getCurrentTime();
    dyn_time times = makeDynTime(now - 2, now - 1, now);

Assign the MindSphereDatapoints to the asset for the upload. The function prepareValues converts the values into a Insights Hub-specific format (grouped by the time stamp).

Upload simultaneous values of an asset always together since Insights Hub deletes the values that were uploaded first. This means simultaneous values of different data points of an asset.

  • int err1 = asset.prepareValues(dp1, values1, times);
    int err2 = asset.prepareValues(dp2, values2, times);

If you select a data point that does not correspond to a MindSphereDatapoint but is assigned to a MindSphereAsset, the function prepareValues returns the error code -1 and the values are not prepared for the upload.

The optional parameter "qualities" is automatically set to "00000000" by the function. For more information on the quality codes, see the MindSphere Documentation

Repeat the steps to add all values, which should be uploaded this time, to the asset. Up to 15.000 values can be uploaded simultaneously.

  • Upload the values. The function uploadPreparedValues uploads all values that were added to the asset by using the function prepareValues (see above), to Insights Hub. If the upload fails, the error code -1 is returned. Use the following code:
  • int err = asset.uploadPreparedValues();

If the function is executed on a passive system, an error code is not returned.

View Values With the MindApp "Fleet Manager"

This paragraph describes how to view the values that were added in the step Upload values via a CTRL Script. Note that in order to view the values, the Insights Hub configuration must be finished (see the chapter Configuration - Insights Hub (Cloud) - Part1 and the other configuration chapters) and the documentation section step Upload values via a CTRL Script must be completed.

For more information on Insights Hub, see the Insights Hub help https://documentation.mindsphere.io/#/kiosk.

Our tests showed that Insights Hub sometimes requires up to 10 minutes in order to display the values using the zoom level set by default. If you limit the time range, the visualization of the values is generally faster.