# MQTT Payload filter?

**URL:** <https://discourse.nodered.org/t/mqtt-payload-filter/37457>\
**Category:** General\
**Created:** [13 December 2020 21:26 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457 "2020-12-13T21:26:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steinspiel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinspiel/32/30095_2.png) [@Steinspiel](https://discourse.nodered.org/u/Steinspiel)\
**Post date:** [13 December 2020 21:26 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/1 "2020-12-13T21:26:39Z")

</div>

My "mqtt in" node receives the following data as "a parsed JSON object"

{"topic":"ergebnis","payload":{"00:ff:9d:4b:20:4a":-92,"1a:a8:bb:d2:10:52":-89,"42:2f:c7:89:75:07":-74,"47:73:dd:2c:e7:d0":-89,"f4:fa:fd:7b:b8:dc":-93},"qos":0,"retain":false,"\_msgid":"e1557ea7.a105f"}

an example:  
MAC Adress: 00:ff:9d:4b:20:4a  
signal strength -92

I would now like to check whether a MAC address is available and if so, its signal strength is then output.

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43e1e07af1adc8078058b72a14507852b0e3fd3a.png)

Can someone tell me how to configure the nodes?

Thank you and have a healthy week...

```auto
[{"id":"42d3b500.ac75dc","type":"mqtt in","z":"7492fcf7.7b3014","name":"mqtt BLE Scan","topic":"ergebnis","qos":"0","datatype":"json","broker":"c6a4e385.5b2c4","x":340,"y":420,"wires":[["64992ea6.4c62","13a52c6c.cba4e4","c021516e.7aaf2"]]},{"id":"c6a4e385.5b2c4","type":"mqtt-broker","name":"mqttbroker","broker":"xxx.xxx.xxx.xx","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 December 2020 23:40 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/2 "2020-12-13T23:40:39Z")

</div>

Do you control how the data is sent? i.e. could you reformat it?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [14 December 2020 07:12 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/3 "2020-12-14T07:12:06Z")

</div>

My solution would be to change the object to an array of objects, eg; `{"mac":"xxxx","signal":xx}` using jsonata and from there you can filter using a function node or with jsonata.

You could try this flow (check the nodes)

```auto
[{"id":"c69460b2.120c38","type":"inject","z":"8dcd4a50.e8563","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"00:ff:9d:4b:20:4a\":-92,\"1a:a8:bb:d2:10:52\":-89,\"42:2f:c7:89:75:07\":-74,\"47:73:dd:2c:e7:d0\":-89,\"f4:fa:fd:7b:b8:dc\":-93}","payloadType":"json","x":194,"y":168,"wires":[["4f3521f3.530858"]]},{"id":"4f3521f3.530858","type":"change","z":"8dcd4a50.e8563","name":"set array of objects","rules":[{"t":"set","p":"payload","pt":"msg","to":"$each(payload.$, function($v, $k) { {\"mac\":$k,\"signal\":$v} })","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":354,"y":168,"wires":[["b0188e23.78d0d8"]]},{"id":"3bc5f239.d71d16","type":"debug","z":"8dcd4a50.e8563","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"signal","targetType":"msg","statusVal":"","statusType":"auto","x":694,"y":168,"wires":[]},{"id":"b0188e23.78d0d8","type":"change","z":"8dcd4a50.e8563","name":"get signal","rules":[{"t":"set","p":"signal","pt":"msg","to":"*[mac=\"00:ff:9d:4b:20:4a\"].signal","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":168,"wires":[["3bc5f239.d71d16"]]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 December 2020 08:54 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/4 "2020-12-14T08:54:25Z")

</div>

Use a split node to create topic/payload messages & a switch node to re-direct them according to MAC...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd855effc5ab2f21203ba85ec5222ff6f7fcb430.png)

```auto
[{"id":"593216b7.d6d248","type":"inject","z":"84634390.8f4c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"00:ff:9d:4b:20:4a\":-92,\"1a:a8:bb:d2:10:52\":-89,\"42:2f:c7:89:75:07\":-74,\"47:73:dd:2c:e7:d0\":-89,\"f4:fa:fd:7b:b8:dc\":-93}","payloadType":"json","x":190,"y":440,"wires":[["baa3743c.d2f258"]]},{"id":"eb234dd.f9905b","type":"switch","z":"84634390.8f4c4","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"00:ff:9d:4b:20:4a","vt":"str"},{"t":"eq","v":"1a:a8:bb:d2:10:52","vt":"str"},{"t":"eq","v":"42:2f:c7:89:75:07","vt":"str"},{"t":"eq","v":"47:73:dd:2c:e7:d0","vt":"str"},{"t":"eq","v":"f4:fa:fd:7b:b8:dc","vt":"str"}],"checkall":"false","repair":false,"outputs":5,"x":490,"y":440,"wires":[["b7ff394e.4bc4f8"],["b62aac2f.1fdeb"],["2f32c44e.edda0c"],["86db3114.65903"],["74371da6.7339e4"]]},{"id":"baa3743c.d2f258","type":"split","z":"84634390.8f4c4","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":350,"y":440,"wires":[["eb234dd.f9905b"]]},{"id":"b7ff394e.4bc4f8","type":"debug","z":"84634390.8f4c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":320,"wires":[]},{"id":"b62aac2f.1fdeb","type":"debug","z":"84634390.8f4c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":380,"wires":[]},{"id":"2f32c44e.edda0c","type":"debug","z":"84634390.8f4c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":440,"wires":[]},{"id":"86db3114.65903","type":"debug","z":"84634390.8f4c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":500,"wires":[]},{"id":"74371da6.7339e4","type":"debug","z":"84634390.8f4c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":560,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Steinspiel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinspiel/32/30095_2.png) [@Steinspiel](https://discourse.nodered.org/u/Steinspiel)\
**Post date:** [14 December 2020 19:15 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/5 "2020-12-14T19:15:50Z")

</div>

> [@bakman2](#):
>
> My solution would be to change the object to an array of objects [...]

Hello,

I didn't know "jsonata" before, but it works very well!

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6cefe7ee833a5f3b8bebf1a29faf4398819346f3.png)

Thank you for your help

---

<div class="post-metadata">

**Author:** ![Steinspiel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinspiel/32/30095_2.png) [@Steinspiel](https://discourse.nodered.org/u/Steinspiel)\
**Post date:** [14 December 2020 19:19 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/6 "2020-12-14T19:19:42Z")

</div>

> [@Steve-Mcl](#):
>
> Use a split node to create topic/payload messages [...]

Hello,

I haven't used the "spilt node" yet.  
That works for me too!

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b1728d6144a9d961a1fff43ff7307bcb2422780.png)

Thanks for your help

---

<div class="post-metadata">

**Author:** ![Steinspiel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinspiel/32/30095_2.png) [@Steinspiel](https://discourse.nodered.org/u/Steinspiel)\
**Post date:** [15 December 2020 19:47 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/7 "2020-12-15T19:47:33Z")

</div>

> [@Steve-Mcl](#):
>
> Verwenden Sie einen geteilten Knoten, um Themen- / Nutzdatennachrichten zu erstellen

Hallo,  
I have no further question: How do I have to configure the "Split Node" so that the signal is not displayed, but the MAC addresses ?

Danke,

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 December 2020 19:51 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/8 "2020-12-15T19:51:32Z")

</div>

> [@Steinspiel](#):
>
> How do I have to configure the "Split Node" so that the signal is not displayed,

What do you mean? the split node does not display anything.

You can change the DEBUG nodes to show `msg.topic`

---

<div class="post-metadata">

**Author:** ![Steinspiel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinspiel/32/30095_2.png) [@Steinspiel](https://discourse.nodered.org/u/Steinspiel)\
**Post date:** [15 December 2020 20:53 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/9 "2020-12-15T20:53:41Z")

</div>

Hello,

> [@Steve-Mcl](#):
>
> What do you mean?

I think the "split node" will do the payload so the signal strength will be, right?  
But I also want to see the MAC addresses from the payload. Is that possible?

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d91db2e7ebfbedc2918f3628287582d6edfb2f1.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 February 2021 20:53 UTC](https://discourse.nodered.org/t/mqtt-payload-filter/37457/10 "2021-02-13T20:53:52Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
