OnChange mechanisms

The OnChange mechanism is primarily intended for use with the SendDataAsString mechanism. There are various references to the use of this mechanism.

Difference between the different methods

The SendData method and the SendDataAsString method are sent as retain messages. This has the effect that a newly connected app automatically has the most recently sent data available, even if no data is currently being sent.

If the respective OnChange methods are used, the messages are not sent as retain messages. With a new connection, the current status of the data should be sent as a retain message so that the newly connected app instance also has the current status of the data available. Further information on the OnChange methods can be found at SendData_OnChange and SendDataAsString_OnChange.

Adding variables/widgets

If the SendDataAsString mechanism is used, a certain structure of the JSON document must be taken into account. If changes (add/delete or adjust) are made to the structure between two calls, the following points must be observed:

Additional Notes

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.