Custom payload

Custom payloads let MQTT Publisher send data to systems that do not use the default payload structure.

Default and custom payloads

The default payload uses a fixed JSON structure. A custom payload uses String Formatter templates to change field names, nesting, or plain-text output.
Default and custom payload comparison
Aspect
Default payload
Custom payload
Use case
Use when the receiving system accepts the built-in JSON structure.
Use when the receiving system requires different field names, nesting, or plain text.
Structure
The payload structure is fixed. For an example, see MQTT.
The header, records, or both use String Formatter templates.
Publisher configuration
Leave
PF Enabled
disabled.
Enable
PF Enabled
, then define
PF Header
and, if required,
PFRecord
.
Subscriber compatibility
The MQTT Subscriber expects the default JSON payload. See Default JSON subscription.
This topic describes publisher formatting only.
Arrays and complex data types
Arrays are supported only in the default payload format. For more information, see Publishing complex data types.
Use the default payload format when you publish arrays.
IMPORTANT: MQTT Subscriber expects the default JSON payload. This topic describes custom formatting for MQTT Publisher.
A custom payload can include a header, records, or both. For example:
{ "timestamp": "...", "sensors": [ { "name": "MyVariableA", "value": 23 }, { "name": "MyVariableB", "value": true }, { "name": "MyVariableC", "value": "abc" } ] }
General payload structure
Callout presenting the structure of a payload, with distinct header and
                        record pattern presented.
FactoryTalk® Optix™
uses String Formatter dynamic links with MQTT Publisher payload formatter properties:
PF Enabled
,
PF Header
, and
PFRecord
.
TIP: In String Formatter, select JSON compliant format when records include multiple data types. For more information, see String formatter data types.

Payload formatter components

PF Header
:
  • Defines the header portion of the payload.
  • Uses String Formatter to define JSON, plain text, or mixed text with dynamic values.
  • Can include one or more variables, such as a timestamp or production line number.
  • Uses the
    #PFRecord
    placeholder when the header inserts record output.
  • Uses square brackets around
    #PFRecord
    when multiple variables form a JSON array.
  • If multiple variables exist in a folder,
    FactoryTalk Optix
    iterates through the variables during payload creation.
PFRecord
:
  • Defines the repeated record portion of the payload.
  • Uses String Formatter dynamic links to map alias item attributes, such as browse name and value.
  • Can remain blank when the payload does not use repeating records.
TIP: In String Formatter, escape the first opening brace to prevent a syntax error. Double the brace to escape it. For example:
{{{0}

Custom payload examples

These examples show String Formatter formats and dynamic links for
PF Header
and
PF Record
.
  • PF Header
    String formatter format:
    {"timestamp":"{0:o}","sensors":[#PFRecord]}
    Dynamic link (0):
    MQTT/MQTTClient/MQTTPublisher/PayloadUpadteTimestamp
    . Placeholder
    {0:o}
    maps to this link.
    Placeholder
    #PFRecord
    inserts the formatted
    PF Record
    output into the sensors array.
  • PF Record
    String formatter format:
    {"name":"{0}","value":{1}},
    Dynamic link (0):
    {Item}@BrowseName
    . Placeholder
    {0}
    maps to this link.
    Dynamic link (1):
    {Item}@Value
    . Placeholder
    {1}
    maps to this link.
For the fixed default payload structure, see MQTT. For arrays and complex data types in the default payload format, see Publishing complex data types.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal