Using Callback Properties

A number of objects offer Callback (CB) properties that can host a Lua script which is then executed when a specific event related to the object occurs (like receiving data).

Some Callbacks allow the pre-processing of incoming or outgoing data while others can be used to create custom actions independent from the data. Generally the name of a callback property indicates the functionality of the callback and when it is triggered. As Callback properties are closely related to the type of object to which they belong, each callback function’s parameters and return data are specific to the individual object type and the callback itself. The default setting for each callback property is an empty skeleton callback function illustrating the parameters and return values.

In this example the

Preprocess Outgoing Messages callback property of the MQTT Datasource Interface is used to illustrate how the skeleton function reveals the parameters and returned data:

return function(oid, mid, topic, payload, qos, retain) (1)
    return topic, modified_payload, qos, retain (2)
end

1 oid, mid, topic, payload, qos, retain are the different parameters provided by the object for possible processing.

2 the data (including the modified payload instead of the original payload) is returned to the object

More information on the individual Callback properties is available in Properties table of the Object Model Reference, using the search functionality to navigate to the specific property.