External mqtt incoming values

hello!
i’m triyng to filter some incoming messages from an external mqtt broker. i do this creating asset items and linking them to an mqtt agent. at the subscribe link (one for all kynd of messages) i receive datas. i have 2 kind of data: a read with some parameters and a temperature. when $.command is “sensor.read” i have some other field like $.target_type field, while when $.command is “sensor.temperature” i have $.temperature but no $.target_type. so i want to distinguish messages using message match filters and predicate (but correct me if is wrong way).
i have some questions:

  1. is it possible to have a unique agent and populate all the fields at once when i get a payload? (is $.command is “sensor.read” i have multiple values i’m interested in)
  2. see this screenshot: why the filter doesn’t works? as you can see the target_type field is filled by a wrong payload.

with working filter i will need to populate my value using “Value Filters”, JSON path, $.target_type

thank you so much

Hi,

I’m having some trouble following what you exactly want to do. But some quick tips that might help you:

  • I think you should be using value filter to get the data you want from the JSON object you receive.
  • You can receive data in 1 attribute, and write to other attributes from there to get the individual values in attributes using ‘Attribute link’. See this example: Asset Attribute with JSON Object and store data points to Line Chart - #2 by Don
    As you can see it is an array, so you can write from one to many.

I hope this helps, otherwise maybe you can share a sample of the data you are receiving and how you want to distribute it over asset attributes.

Don

Hi Don,
thank you so much, works like a charm! since i’ve not found the info in the wiki: what’s the meaning of returnFirst and returnLast booleans?

only last thing: i can receive 2 type of payloads:

{“command”:“sensor.read”,“result”:“OK”,“target_type”:“motion”,“target_distance”:35,“target_energy”:34}

and

{“command”:“sensor.temperature”,“result”:“OK”,“temperature”:33.125}

and these are the filters following your guide

[
{
“ref”: {
“id”: “5x4Zn1aI7tBZLEx7WnGZFn”,
“name”: “command”
},
“filters”: [
{
“type”: “jsonPath”,
“path”: “$.command”,
“returnFirst”: true,
“returnLast”: false
}
]
},
{
“ref”: {
“id”: “5x4Zn1aI7tBZLEx7WnGZFn”,
“name”: “lux”
},
“filters”: [
{
“type”: “jsonPath”,
“path”: “$.lux”,
“returnFirst”: true,
“returnLast”: false
}
]
},
{
“ref”: {
“id”: “5x4Zn1aI7tBZLEx7WnGZFn”,
“name”: “temperature”
},
“filters”: [
{
“type”: “jsonPath”,
“path”: “$.temperature”,
“returnFirst”: true,
“returnLast”: false
}
]
},
{
“ref”: {
“id”: “5x4Zn1aI7tBZLEx7WnGZFn”,
“name”: “target_type”
},
“filters”: [
{
“type”: “jsonPath”,
“path”: “$.target_type”,
“returnFirst”: true,
“returnLast”: false
}
]
},
{
“ref”: {
“id”: “5x4Zn1aI7tBZLEx7WnGZFn”,
“name”: “target_distance”
},
“filters”: [
{
“type”: “jsonPath”,
“path”: “$.target_distance”,
“returnFirst”: true,
“returnLast”: false
}
]
},
{
“ref”: {
“id”: “5x4Zn1aI7tBZLEx7WnGZFn”,
“name”: “target_energy”
},
“filters”: [
{
“type”: “jsonPath”,
“path”: “$.target_energy”,
“returnFirst”: true,
“returnLast”: false
}
]
}
]

function works but when i receive temperature, target_type (text) becomes null. is it possible to avoid this?