Hey. I need to subscribe to multiple MQTT topics using a single MQTT node. Is that a good way to simplify the flow as I do not want to create a MQTT subscribtion node for every remote device that I have.
I might have 50 remote devices that I need to listen to, and I certainly dont want to create 50 individual MQTT nodes.
[{"id":"ff173687.543bf8","type":"mqtt in","z":"df177cb8.27882","name":"","topic":"device1/number_to_pick","qos":"2","datatype":"auto","broker":"2727c5a5.a4fb6a","x":350,"y":400,"wires":[["c5854ac5.fde828"]]},{"id":"9e91a191.4a7a9","type":"debug","z":"df177cb8.27882","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":400,"wires":[]},{"id":"c5854ac5.fde828","type":"function","z":"df177cb8.27882","name":"Generate SQL","func":"//add the values to the msg so they can be debugged and used later\nquantity = msg.payload\n\n//msg.topic=\"UPDATE pack_to_light SET Quantity = 0 WHERE Device = 'device1'\"\nmsg.topic=`UPDATE pack_to_light SET Quantity = '${quantity}' WHERE Device = 'device1'`\n//msg.topic=`REPLACE INTO pack_to_light (Device,Item,Serial) VALUES ('${msg.device}','${msg.item}',${msg.serial})`;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":400,"wires":[["9e91a191.4a7a9","97fe0f98.1e2a3"]]},{"id":"97fe0f98.1e2a3","type":"mysql","z":"df177cb8.27882","mydb":"97be0e96.67231","name":"Add item to database","x":800,"y":480,"wires":[[]]},{"id":"2727c5a5.a4fb6a","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"workshop/status","birthQos":"1","birthRetain":"true","birthPayload":"online","closeTopic":"workshop/status","closeQos":"1","closeRetain":"true","closePayload":"offline","willTopic":"workshop/status","willQos":"1","willRetain":"true","willPayload":"disconnected"},{"id":"97be0e96.67231","type":"MySQLdatabase","z":"","name":"","host":"localhost","port":"3306","db":"test","tz":""}]
So this is a flow for 1 MQTT subscribe node. I am just listening and ocasionally a device sends a message. After receiving a message, I need to update MYSQL table.
quantity = msg.payload
msg.topic=`UPDATE pack_to_light SET Quantity = '${quantity}' WHERE Device = 'device1'`
return msg;
How can I change the current nodes to listen for lets say 20 devices? (devices1,devices2,devices3,devices4 .......) As you can see now, I am only listening to one device:
device1/number_to_pick
Also, what would happen if multiple devices send a mqtt message at the same time?