How To? Multiple Source MQTT Publishing

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

How To? Multiple Source MQTT Publishing

#1 Post by prairietech » 07 Apr 2020, 22:03

Using Node Red to control lights with MQTT. Currently I have one esp8266 running espeasy and 4 inputs with pushbuttons each with its own topic. So far it works great!
Now I'm thinking I could use maybe 3 more of these esp8266s with pushbuttons in various parts of my house.
Instead of having 4 individual mqtt subscribe nodes for each of 3 Node Red inputs for light control, can I duplicate the Unit Name of the 3 additional esp8266s with different Unit Numbers?
This way all of the published topics are the same but coming from 4 different sources. The esp8266s only publish and are not subscribed to any topic.

TD-er
Core team member
Posts: 8739
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How To? Multiple Source MQTT Publishing

#2 Post by TD-er » 07 Apr 2020, 22:44

I am not sure if I understand your suggestion.
A lot of nodes may subscribe or publish to the same topic.
But on the receiving end you must make sure you can differentiate.

The publish topic can be configured containing system variables.
A client can subscribe to match several topics by placing a # in strategic place.
So you can also publish to separate topics and read them all via a single subscription string.

Is that what you need?

User avatar
ThomasB
Normal user
Posts: 1065
Joined: 17 Jun 2018, 20:41
Location: USA

Re: How To? Multiple Source MQTT Publishing

#3 Post by ThomasB » 08 Apr 2020, 00:15

... can I duplicate the Unit Name of the 3 additional esp8266s with different Unit Numbers?
I propose a different solution. Go to ESPEasy Controller's setup page and edit the MQTT Controller Publish entry. It defaults to this:

Code: Select all

%sysname%/%tskname%/%valname%
Instead of using the %sysname% variable, you can hard-code the name. That is to say, copy the main device's system name onto the three duplicated devices. Or all four devices can use the same hard-coded name (which does not need to match any device's %sysname%). Like This:

Code: Select all

COMMON_HARD_CODED_NAME/%tskname%/%valname%
BTW, if you are using rules for the MQTT then be sure to update their publish statements with the new naming convention.

Now the published messages from the four switch controller devices will appear as if they came from the same source.

- Thomas

prairietech
Normal user
Posts: 31
Joined: 20 Oct 2017, 23:47

Re: How To? Multiple Source MQTT Publishing

#4 Post by prairietech » 08 Apr 2020, 02:25

Thanks! That was the information I was looking for. I didn't see any reason why naming the 4 espeasy devices with the same name would cause any conflict within themselves. I'll move forward with building additional button panels.
Espeasy has really made it possible for non-coders like myself to accomplish some otherwise complicated processes.

Post Reply

Who is online

Users browsing this forum: No registered users and 106 guests