Custom Payload
Overview
You can transform a default message payload to a custom payload schema using a jq filter. For additional information see jq's website.
ThingsPro Edge
ThingsPro Edge offers a convenient interface to apply jq filters to messages and test the result of the transformation to a custom payload. Here are some examples.
Default D2C message schema
In the telemetry (D2C) settings, select the tags that you want to include from the left panel to show the default result on the right panel.
Custom payload after transformation
Enable the custom payload option and enter the jq filter to see the result of the transformation.
ThingsPro Tags Keys
You can use the ThingsPro tag keys listed here to define the message format.
prvdName: provider name of tag
srcName: source name of tag
tagName: tag name
dataValue: tag value
ts: time stamp of tag value be collected
dataType: data type of tag value, example: int64.
Example
Tags
{
"dataType": "int32",
"dataValue": 11,
"prvdName": "modbus_tcp_master",
"srcName": "A1",
"tagName": "status",
"ts": 1581659603000000
}Format (applying the jq filter)
{
device: .srcName,
timestamp: (now|todateiso8601),
tag: [
{
name: .tagName,
value: .dataValue
}
]
}Result of the transformation
{
"device": "A1",
"tag": [
{
"name": "status",
"value": 11
}
],
"timestamp": "2020-11-10T03:58:16Z"
}Note: If you add variable value as a key in the JSON element, use parentheses as in the following example:
Format (applying the jq filter)
{
(.tagName): .dataValue
}Result of the transformation
{
"status": 11
}
JSON message merge behavior
A custom payload transforms
each tag
into the format you want and merge it into the final message buffer.The format (application of the jq filter) of the custom payload in a message group affects the format of the buffered message.
JSON merge mode consists of
object override
andarray append
.- The object overide mode is often used to record only the last value.
format setting(jq filter):
{
(.tagName): .dataValue,
ts: .ts
} - The array append mode is often used to record all values.
format setting(jq filter):
{
(.tagName): [
{
value: .dataValue,
ts: .ts
}
]
}
- The object overide mode is often used to record only the last value.
Last updated on 2022-07-22 by Cecilia Fernandes