# Combine multiple mqtt messages into one measurement for influx

**URL:** <https://discourse.nodered.org/t/combine-multiple-mqtt-messages-into-one-measurement-for-influx/44176>\
**Category:** General\
**Created:** [14 April 2021 14:09 UTC](https://discourse.nodered.org/t/combine-multiple-mqtt-messages-into-one-measurement-for-influx/44176 "2021-04-14T14:09:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![connectix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/connectix/32/40296_2.png) [@connectix](https://discourse.nodered.org/u/connectix)\
**Post date:** [14 April 2021 14:09 UTC](https://discourse.nodered.org/t/combine-multiple-mqtt-messages-into-one-measurement-for-influx/44176/1 "2021-04-14T14:09:51Z")

</div>

As a beginner with node-red I don't know where to start so some help would be very appreciated.

I have many sensors reporting themselves by publishing to mqtt topics. They send the following data:  
10\_52\_1C\_66\_1D\_CC/dsmr/smart\_gateways/model = esp-dsmr-4  
10\_52\_1C\_66\_1D\_CC/dsmr/smart\_gateways/mac\_address = 10\_52\_1C\_66\_1D\_CC  
10\_52\_1C\_66\_1D\_CC/dsmr/smart\_gateways/startup\_time = 2021-04-12T12:40:14Z  
10\_52\_1C\_66\_1D\_CC/dsmr/smart\_gateways/running\_firmware\_version = 2021041002  
10\_52\_1C\_66\_1D\_CC/dsmr/smart\_gateways/update\_available = 2021041002  
10\_52\_1C\_66\_1D\_CC/dsmr/smart\_gateways/wifi\_rssi = -63  
10\_52\_1C\_66\_1D\_CC/dsmr/smart\_gateways/use\_blynk = true

Each sensor is publishing it's mac address as the topic prefix.

I want to combine all these different topics into one json message and write it as seperate measurements in influx.

The above topics arrive in sequence every 5 minutes from every sensor. I see this in the debug:

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [14 April 2021 14:37 UTC](https://discourse.nodered.org/t/combine-multiple-mqtt-messages-into-one-measurement-for-influx/44176/2 "2021-04-14T14:37:36Z")

</div>

A simple example of how to split the topic and use one element as topic for join node  
e.g

```auto
[{"id":"4f15f387.24ecc4","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"23:23/eee/eeee/wifi","payload":"231.6","payloadType":"str","x":170,"y":3620,"wires":[["1c88b7e4.483858"]]},{"id":"1c88b7e4.483858","type":"function","z":"5a245aa1.510164","name":"","func":"msg.topic = msg.topic.split(\"/\")[3];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":3640,"wires":[["2af57594.1a21d2"]]},{"id":"7283ee1e.d0796","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"23:56/ff/ffff/rssi","payload":"QTot: 0 ","payloadType":"str","x":150,"y":3680,"wires":[["1c88b7e4.483858"]]},{"id":"2af57594.1a21d2","type":"join","z":"5a245aa1.510164","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":390,"y":3640,"wires":[["759a8f1c.44e9b"]]},{"id":"759a8f1c.44e9b","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":3640,"wires":[]}]

```

 ![Screenshot_20210414-153815](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/3006d05f1c0f023a976c91a77bd5a7be9ca9748e.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 June 2021 14:37 UTC](https://discourse.nodered.org/t/combine-multiple-mqtt-messages-into-one-measurement-for-influx/44176/3 "2021-06-13T14:37:37Z")

</div>

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