Switching between mqtt brokers

I'm working (on my laptop) on a project that uses a dozen or more mqtt nodes. When I'm at home I want them to connect to a broker on my home LAN, but on the road I want to use a broker on my laptop or a public broker. Is there an easy way to make the switch without having to find and open each mqtt node?

What OS are you running? If its Linux or OSX, you could edit /etc/hosts and add an entry to point my-broker at the IP address of the broker and then edit your mqtt nodes to use my-broker in place of the ip address. Then when you move between networks you just need to edit /etc/hosts with the appropriate IP address.

The alternative option would be to use an environment variable. Configure the broker node to use $(MY_BROKER) as the url of the broker. Then ensure that env var is set to the required value when you start node-red.

If you use the environment variable route you could have script run on boot that sets it based on what network it can see...

Or you could just have two mqtt input nodes and don't worry about one failing to connect ever 20 secs.

@knolleary, @dceejay Thanks for the suggestions. I'm running OS X, and the environmental variable idea seems to fit best with my workflow. I'll give it a try.