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

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

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.

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

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".

Hi Christian,

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

Thank you.

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!

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. :slight_smile:

[{"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":[[]]}]

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