List of topic choices in mqtt-in

I'd like to have a fixed list of available topics for the mqtt-in node. As far as I can see, using a subflow is not option, or maybe I am missing something.
In other words, I need that the user - upon deploying the node - has not to type in the topic but should make a choice from a dropdown list.

The mqtt-in node needs the topic hardcoded. If the topics being published have a formal format that they all abide by, you code subscribe to the main topic and then filter the results with switches.

Lets say you have 5 weather stations and you want tp pick the data from station 5. If the topics were arranged like

you could subscribe to 'weatherstation/#' and you would get the data from all the stations. Then you could filter it by the second level in the topic

If you haven't read the MQTT Topics & Best Practices - MQTT Essentials: Part 5 I suggest you spend some time and read it

I have read very well the mqtt essentials, and I know that the mqtt-in need the topic hardcoded. I was just wondering if there could be a possibility not to leave this to the user, who can mistype the topic.

Is the user editing the node? or are they just using a dashboard and picking from a list.

It they are picking it from a list, you can programatically limit what gets to them.

If they are editing the node then, yup tehy can mistype the topic (heck, I've done that multiple times :grin:)

This would, in my opinion, need a different node. MQTT is so flexible that adding this to the standard mqtt-in would add complexity to it that most people would not use.

The nice thing (one of many of course :wink: ) about Node-RED is that it is easy enough to create a new, more specialist node from an existing example.

You can use a subflow to do this.

  1. Set the mqtt-in topic to ${TOPIC}
  2. Wrap that node in a subflow.
  3. Edit the subflow properties and define a property called TOPIC. By expanding the row in the properties table, you can customise the UI for how the property will be shown. One of the options is a select box where you can predefine a set of options.

You made my day, Nick! Thank you.

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