What is more Optimal many MQTT nodes or a Switch Function

Ok , I might be splitting hairs here but what would be more optimal
I have a controller that reports in 18 different mqtt topics. So what would be better

Having 18 MQTT nodes each with their own topic or 1 MQTT node that get split by a function.

Option one


stat/garage/switch2 extr


Function node
switch (msg,topic){
case "stat/garage/switch1" :
return [msg]
case "stat/garage/switch2" :
return [null,msg]
and so on...

I would use wildcards in the MQTT and then a Switch node (not a function node) if it was necessary to split them up. A Switch node more efficient than a Function node.

[Edit] I realise that does not actually answer your question.

[Further Edit, sorry] Also think about what comes after the Switch and if it is actually necessary. Often the processing path for each is very similar and it can be written as one path with all messages going down it and using the topic in code to decide what to do. For example, if the data were to be written to influx then it should be possible to have a mapping of topics to influx fields so it may not be necessary to split the flow at all. That is not always the case of course

Ah that is even better. Some of the payloads need to be "modified" before they go out so then Ill use a function. Thanx for the input!

TBH - whichever is more readable and understandable to you. As long as the MQTT nodes share the same server connection there is no real difference apart from you having to code up the switch vs configuring multiple mqtt nodes. Generally I prefer more mqtt nodes as I can place them into logical flows on the screen based on the topic.

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