Custom Payload
Overview
Custom Payload allow you to transform default payload to your desired payload schema via jq filter. You can access jq web site (https://stedolan.github.io/jq/manual/) for detail information.
Web GUI
ThingsPro Edge Web GUI offered a friendly interface allow you to apply jq filter and test the transform result, here are some example screen shots :
Default D2C message schema
You can select tags via left hand-side tag selector, and, the default result show on right hand-side area.
Custom payload after execute transform
The custom payload will display after you enable custom payload, and input jq Filter.
Detail
ThingsPro's Tag offers below keys for you to compose your 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
tag example:
{
"dataType": "int32",
"dataValue": 11,
"prvdName": "modbus_tcp_master",
"srcName": "A1",
"tagName": "status",
"ts": 1581659603000000
}format(jq filter) example:
{
device: .srcName,
timestamp: (now|todateiso8601),
tag: [
{
name: .tagName,
value: .dataValue
}
]
}transform result:
{
"device": "A1",
"tag": [
{
"name": "status",
"value": 11
}
],
"timestamp": "2020-11-10T03:58:16Z"
}P.S. If you would like to put above variable value as key of JSON element, please use parentheses, such as:
format(jq filter) example:
{
(.tagName)=.dataValue
}transform result:
{
"status": 11
}JSON message merge behavior
Custom payload is to transform
each tag
into the format you want and then merge into the final message buffer.The format(jq filter) of custom payload in a message group affects the format of buffered message.
JSON merge mode is
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 2021-05-03 by Zack YL Shih