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:
- If a variable/widget is added and no change to the order is desired, the ForceUpdate parameter can remain FALSE.
- If a variable/widget is added and a change to the order is desired, the ForceUpdate parameter must be set to TRUE for a call. It should then be set to FALSE again.
- If a variable/widget is deleted, the page in the app must be closed and reopened once.
- If a variable/widget is changed in relation to the metadata (e.g. reconfiguration of a widget), ForceUpdate must be set to TRUE for a call, otherwise only the values of the widget are updated. It should then be set to FALSE again.
Additional Notes
- The bNewAppSubscribe parameter of the FB_IotCommunicator function block goes TRUE for one cycle when a new app instance connects to the topic on the message broker. This parameter can be used to identify the right time to send a retain message.
- The nActiveAppInstances parameter of the FB_IotCommunicator function block specifies the number of connected app instances. If no app is connected, no data is sent in order to save performance and data volume.
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. |