mcUploadValues()

Uploads the data to the MindSphere Server.

Synopsis

int mcUploadValues(uint assetId, mapping data);

Parameters

Parameter Description
assetId Defines to which asset the values will be uploaded.
data

The parameter "data" Is a mapping consisting of multiple MindSphere Timestamps as keys. The values assigned to those keys are mappings containing all values associated with this timestamp.

The mapping translated to the JSON format could look like this (timestampX must be replaced by a MindSphereTimeFormat string and MindSphereDatapointNameX must be replaced by a MindSphere Data point name existing in your WinCC OA project):

{

"timestamp1": {

"MindSphereDatapointName1":

{

"value": 1,

"quality": "00000000"

},

"MindSphereDatapointName2":

{

"value": 3,

"quality": "11000000"

},

"MindSphereDatapointName3":

{

"value": 3.6,

"quality": "00000000"

}

},

"timestamp2": {

"MindSphereDatapointName1":

{

"value": 6,

"quality": "00000000"

},

"MindSphereDatapointName3":

{

"value": 3.7,

"quality": "00000000"

}

}

}

Return Value

The function mcConnectAsset returns 0 when it was successfully executed and -1 if either arguments are missing, assetId does not exist or there is a problem when establishing a connection.

Errors

The function mcUploadValues returns 0 when it was successfully executed and -1 if either arguments are missing, assetId does not exist or there is a problem when establishing a connection.

Description

When using this function, note that only MindSphere Data point names can be added to the data mapping that is part of the MindSphere Asset corresponding to the assetId parameter. When using the CTRL++ class MindSphereAsset this is checked automatically.

Since MindSphere groups uploaded values by timestamp and replaces already existing timestamps when re-uploading values, upload all values that contain the same timestamp at once.

MindSphere uses the following timestamp format 2018-10-10T06:22:53.683Z. Use this format. This format can be created by using the getMindSphereTimeFormat function (you can find the function in wincc_oa_path/scripts/libs/classes/mindSphere/MindSphereAsset). If the timestamp key of the data mapping has a different format, the upload of the values will not work.

For a functionality as in the WinCC OA functions such as dpGetPeriod, use the CTRL++ class MindSphereAsset.

When re-uploading a timestamp to the MindSphere Server, the previously uploaded timestamp and all values it contains will be deleted. This is a limitation of MindSphere and not of WinCC OA.

Example

#uses "CtrlMindConnect"
#uses "classes/mindSphere/MindSphereAsset"

void main()
{
    string dp = "NameOfMindSphereAsset";  /* This MindSphere Asset must already exist */

    uint assetId;
    int err = mcNewAsset(getMappingFromAssetDP(dp), assetId);
    mapping data;

    time now = getCurrentTime();
    time timeOfTimestamp1 = now - 1;
    time timeOfTimestamp2 = now;

    mapping timestamp1;
    mapping timestamp2;
    mapping mindSphereDatapointName1;
    mapping mindSphereDatapointName2;
    mapping mindSphereDatapointName3;

    //add value and quality to the mapping representing the first MindSphere Data point

    mindSphereDatapointName1[value] = 1;
    mindSphereDatapointName1[quality] = "00000000";

    //add value and quality to the mapping representing the second MindSphere Data point

    mindSphereDatapointName2[value] = 3;
    mindSphereDatapointName2[quality] = "11000000";

    //add value and quality to the mapping representing the third MindSphere Data point

    mindSphereDatapointName3[value] = 3.6;
    mindSphereDatapointName3[quality] = "00000000";

    //add the mappings representing the MindSphere Data points to the timestamp mapping which should contain these values.

    timestamp1["mindSphereDatapointName1"] = mindSphereDatapointName1;
    timestamp1["mindSphereDatapointName2"] = mindSphereDatapointName2;
    timestamp1["mindSphereDatapointName3"] = mindSphereDatapointName3;

    //change value and quality for the first MindSphere Data point

    mindSphereDatapointName1[value] = 6;
    mindSphereDatapointName1[quality] = "00000000";

    //change value and quality for the third MindSphere Data point

    mindSphereDatapointName3[value] = 3.7;
    mindSphereDatapointName3[quality] = "00000000";

    //add the mappings representing the MindSphere Data points to the next timestamp mapping.

    timestamp2["mindSphereDatapointName1"] = mindSphereDatapointName1;
    //timestamp2["mindSphereDatapointName2"] = mindSphereDatapointName2; this could be done, but because there is no value change it is not necessary
    timestamp2["mindSphereDatapointName3"] = mindSphereDatapointName3;

    //add both timestamps to the data mapping, the key must be the time in the MindSphere Timeformat.

    data[getMindSphereTimeFormat(timeOfTimestamp1)] = timestamp1;
    data[getMindSphereTimeFormat(timeOfTimestamp2)] = timestamp2;

    if(err == 0)
    {
      err = mcConnectAsset(assetId);
      if(err == 0)
    {

    //values are uploaded here

    err = mcUploadValues(assetId, data);
    DebugTN(err);
}

Assignment

MindSphere

Availability

UI

See also

mcNewAsset()