# Send several messages to a single MQTT output for a matrix display

**URL:** <https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298>\
**Category:** General\
**Created:** [5 February 2020 07:48 UTC](https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298 "2020-02-05T07:48:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![foskolo](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@foskolo](https://discourse.nodered.org/u/foskolo)\
**Post date:** [5 February 2020 07:48 UTC](https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298/1 "2020-02-05T07:48:39Z")

</div>

Hi,

I'm trying to send some values from sensors in my house (temperatures, door switches...) to a single line matrix display (1x8) which is connected to a Wemos (ESP8266).

For single sensor all works fine.

Now I want to send more different sensor values cyclically through a single MQTT output node.

All the sensor values come in through MQTT input nodes. To send the values to the Wemos I created a MQTT output node with the topic "myValues".

This node should send the sensor values cyclically (Sensor1 - wait some seconds - Sensor2 - wait some seconds - Sensor3 - wait some seconds - Sensor1 again...) to the matrix display (connected to the Wemos that subscribes the topic "myValues").

How could solve the problem?

Thanks!

Karlo

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [5 February 2020 08:45 UTC](https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298/2 "2020-02-05T08:45:04Z")

</div>

I assume you have a single line matrix display.  
You can try an infinite loop with a delay node in between.  
As I’m more the JavaScript person I would use a function node storing the data in the nodes context (array preferred because it is easier to iterate). Then send out a value to be displayed together with the index.  
When a message including the index comes back increment the index (or reset if \>areay.length-1) and send this one.  
If a message without the index arrives store/update it and either do nothing or send this one as it is the most recent.  
The timing can be adjusted by the delay node.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 February 2020 09:49 UTC](https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298/3 "2020-02-05T09:49:50Z")

</div>

If the values are arriving fairly regularly then the easiest way to do this is to use a delay node configured as below

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

Each incoming message needs to have a different msg.topic set - (one for each sensor). and then follow this with the mqtt out node with the topic set to "myValues".

---

<div class="post-metadata">

**Author:** ![foskolo](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@foskolo](https://discourse.nodered.org/u/foskolo)\
**Post date:** [5 February 2020 10:02 UTC](https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298/4 "2020-02-05T10:02:03Z")

</div>

Hi Christian,

I will try the "infinite loop", unfortunately I'm non a JavaScript person.

Thank you.

---

<div class="post-metadata">

**Author:** ![foskolo](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@foskolo](https://discourse.nodered.org/u/foskolo)\
**Post date:** [5 February 2020 10:04 UTC](https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298/5 "2020-02-05T10:04:17Z")

</div>

Hi dceejay,

ist seem to be simple. Some values arrives "fairly regularly" (temperatures), but some not (doors and windows sensors).

I'll try it.

Thank you!

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [5 February 2020 10:16 UTC](https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298/6 "2020-02-05T10:16:34Z")

</div>

Here is basic flow. It is not complete solution and needs many modifications to be error proof. But I hope it makes the overall concept clear. 🙂

```auto
[{"id":"c8162f53.5016","type":"function","z":"34b4a5e.a6f4b5a","name":"display data cycle","func":"var targets = global.get('displaytargets')\n\nvar current = context.get(\"current\") || 0\ncurrent += 1 \nif(current > targets.length - 1){\n current = 0\n}\ncontext.set(\"current\",current)\n\nvar sensordata = global.get(targets[current])\n\nmsg.payload = sensordata.name+\":\"+sensordata.value + sensordata.unit\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":820,"wires":[["4103aa1c.c72664"]]},{"id":"62e2d248.f4d99c","type":"function","z":"34b4a5e.a6f4b5a","name":"store globally","func":"var tempsensor = {name:\"temperature\",value:25,unit:\"°C\"}\nvar humiditisensor = {name:\"humidity\",value:56,unit:\"%\"}\nvar doorsensor = {name:\"door\",value:'open',unit:\"\"}\nvar lightsensor = {name:\"light\",value:38,unit:\"lx\"}\n\nglobal.set([\"tempsensor\",\"humiditisensor\",\"doorsensor\",\"lightsensor\"],[tempsensor,humiditisensor,doorsensor,lightsensor])\nglobal.set(\"displaytargets\",[\"tempsensor\",\"humiditisensor\",\"doorsensor\",\"lightsensor\"])","outputs":1,"noerr":0,"x":510,"y":700,"wires":[[]]},{"id":"f3c2a68.f334e58","type":"inject","z":"34b4a5e.a6f4b5a","name":"init objects","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":320,"y":700,"wires":[["62e2d248.f4d99c"]]},{"id":"403bb2ea.4302dc","type":"inject","z":"34b4a5e.a6f4b5a","name":"2 seconds","topic":"","payload":"","payloadType":"date","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"x":330,"y":820,"wires":[["c8162f53.5016"]]},{"id":"4103aa1c.c72664","type":"debug","z":"34b4a5e.a6f4b5a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":820,"wires":[]},{"id":"7c93dd76.a723f4","type":"inject","z":"34b4a5e.a6f4b5a","name":"simulate changes","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":760,"wires":[["dd609eb6.99d82"]]},{"id":"dd609eb6.99d82","type":"function","z":"34b4a5e.a6f4b5a","name":"store temperature change","func":"var random = 20 + Math.floor(Math.random()*6)\nvar sensor = global.get(\"tempsensor\")\nsensor.value = random\nglobal.set('tempsensor',sensor)\n","outputs":1,"noerr":0,"x":550,"y":760,"wires":[[]]}]

```

---

<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:** [5 April 2020 10:16 UTC](https://discourse.nodered.org/t/send-several-messages-to-a-single-mqtt-output-for-a-matrix-display/21298/7 "2020-04-05T10:16:40Z")

</div>

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