SendDataAsString

SendDataAsString 1:

This method is called once to send data to the broker. Unlike the classic SendData() method, the JSON document is passed directly at this point. In this way, the user achieves greater flexibility, but in return must send a correctly constructed JSON document to the app.

The method is intended for users experienced in handling JSON documents. In case of incorrectly formatted JSON documents, the information cannot be displayed in the app.

Syntax

METHOD SendDataAsString : BOOL
VAR_INPUT
    sJsonString : POINTER TO STRING;
    nJsonLen    : UINT;
END_VAR

SendDataAsString 2: Return value

Name

Type

Description

SendDataAsString

BOOL

The method returns the return value TRUE if the call was successful.

SendDataAsString 3: Inputs

Name

Type

Description

sJsonString

POINTER TO STRING

Pointer to the JSON string to be sent.

nJsonLen

UINT

Length of the JSON string

Possible errors are output at the outputs bError and hrErrorCode of the function block instance.

Structure TwinCAT JSON

The TwinCAT IoT Communicator product range uses a JSON format called TwinCAT JSON for communication: the structure of a TwinCAT JSON document is described below using the widgets Socket and Ventilation as an example.

{
    "Timestamp" : "2022-08-04T07:15:06.176",
    "GroupName" : "Widget Testpage",
    "Values" : {
        "sPageDesc" : "TwinCAT JSON Page",
        "stPlug" : {
            "sDisplayName" : "",
            "bOn" : true,
            "sMode" : "Manual",
            "aModes" : [ "Manual", "Automatic" ]
        },
        "stVent" : {
             "sDisplayName" : "",
             "bOn" : true,
             "nValue" : 725,
             "nValueRequest" : 400,
             "sMode" : "Manual",
             "aModes" : [ "Manual", "Automatic" ]
        }
    },
    "MetaData" : {
        "sPageDesc" : {
            "iot.DisplayName" : "Info",
            "iot.ReadOnly" : "true"
        },
        "stPlug" : {
            "iot.DisplayName" : "Plug Widget",
            "iot.ReadOnly" : "false",
            "iot.WidgetType" : "Plug",
            "iot.PlugModeVisible" : "true",
            "iot.PlugModeChangeable" : "false"
        },
        "stVent" : {
            "iot.DisplayName" : "Ventilation Widget",
            "iot.ReadOnly" : "false",
            "iot.WidgetType" : "Ventilation",
            "iot.VentilationSliderVisible" : "true",
            "iot.VentilationValueRequestVisible" : "false",
            "iot.VentilationModeVisible" : "true",
            "iot.VentilationModeChangeable" : "false"
         },
        "stVent.nValue" : {
            "iot.Unit" : "ppm",
            "iot.MinValue" : "400",
            "iot.MaxValue" : "1400"
        }
    },
"ForceUpdate":false
}

Range

Description

Timestamp

Must contain a timestamp per message in the format: "YYYY-MM-DDThh:mm:ss.fff" e.g. "2022-08-04T07:15:06.176".

GroupName

Name of the entry node of the Communicator function block in the app.

Values

The values to be displayed, starting on the first page, with subsequent nesting.

MetaData

Everything that is implemented in PLC attributes (for example, the configuration of widgets).

ForceUpdate

Optional parameter. Is used in the OnChange mechanism to trigger an update after changes. More accurate information can be found at OnChange mechanisms.