How to communicate send separate data to different client Raspberry Pi

Hello everyone, I am new to Node-Red and I need your help here.
I have four PI4 with Node-Red running on them. One of the PI will have a dashboard with a dropdown menu(3 options). If one of the options is selected, I need to send a command to one of the client Raspberry Pi and similarly two rest options to two different client Raspberry Pi. I tried looking at MQTT Publish and Subscribe but I didn't much so can someone please help me to do this in the easiest way.
Your help will be highly appreciated.

What mqtt broker did you use?
Here is an example, it is using afree broker at broker.hivemq.com enter this in to the sever config as below

[{"id":"e9df6e3b.8dfc98","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Mypi/topic1","payload":"send","payloadType":"str","x":210,"y":3440,"wires":[["5124f89b.ab0768"]]},{"id":"5124f89b.ab0768","type":"mqtt out","z":"8d22ae29.7df6d","name":"","topic":"","qos":"","retain":"","broker":"35ccc936.fc2256","x":430,"y":3440,"wires":[]},{"id":"e767981e.7ebfd8","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Mypi/topic2","payload":"send2","payloadType":"str","x":230,"y":3480,"wires":[["5124f89b.ab0768"]]},{"id":"a6defd0d.909bc8","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Mypi/topic3","payload":"send3","payloadType":"str","x":230,"y":3520,"wires":[["5124f89b.ab0768"]]},{"id":"a04868c4.bbbb58","type":"mqtt in","z":"8d22ae29.7df6d","name":"","topic":"Mypi/topic1","qos":"2","datatype":"auto","broker":"35ccc936.fc2256","x":390,"y":3380,"wires":[["3d134d42.123282"]]},{"id":"3d134d42.123282","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":620,"y":3380,"wires":[]},{"id":"72d6315b.564008","type":"mqtt in","z":"8d22ae29.7df6d","name":"","topic":"Mypi/+","qos":"2","datatype":"auto","broker":"35ccc936.fc2256","x":360,"y":3320,"wires":[["5c9a87a7.5409b8"]]},{"id":"5c9a87a7.5409b8","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":550,"y":3300,"wires":[]},{"id":"35ccc936.fc2256","type":"mqtt-broker","z":"","name":"free","broker":"broker.hivemq.com","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

edit updated flow as i think some nodes were missing

It will be on a local network so I used the Server RI4 (with dashboard) as the server (like 192.168.0.100)

Not sure what server R14 is
Try installing mosquitto on one of your pi's

I think you misunderstood me. I am very noob at this things so cannot explain very well.
Let me explain again so,
I have lighting system which will be on a local network(No internet). I have a Raspberry Pi 4 with NodeRed and I have made a dashboard which says Light One, Light Two, Light Three.

Then I have 3 more Raspberry Pi on the other side with NodeRed on them as well. So basically what I am trying to do is when I select the Light 1 on the dashboard, I should send a message(whatever like Hello World for now) only to the first client Raspberry Pi, when I select Light 2 then it should send another message only to the second client Raspberry Pi.
I was doing some research and many said MQTT helps but don't know how to use MQTT. Please help me with some more detailed info

You really need to spend some time reading up about MQTT to get a basic understanding.
This is probably a good place to start - MQTT Essentials - All Core Concepts Explained

Once you understand the basics, I would recommend using node-red-contrib-aedes as a broker because it's very easy to install and use, and will work on a local system with no internet.

Have you tried my example. could you get it working?

The mqtt node could be on any local pi. When they are linked to the broker and subscribed to a topic, they will receive all messaged published to the topic.

Have a reed about it on link Paul has provided, then try my example it has 3 topics, and two examples of how to subscribe to a single topic or all topics. It also shows how to send to a topic.

Yes it works but I have a question. In the mqtt broker server, can I use the broker.hivemq.com in the local network without the internet ?

No you will have to install a broker on the local network, On my debian it was as easy. Just follow the instructions in the link, in above posts.
i just did
apt-get install mosquitto
and to run
mosquitto
You should also look to run it as a service to restart on reboots.

Once running just add the ip of the device it is installed on as the broker host name in the mqtt nodes ,and off you go.

Just noting that on a Pi (Raspbian) or Ubuntu, mosquitto automatically installs as a service that starts on boot, so for a basic setup you don't need to do anything other than
sudo apt install mosquitto
and you will be up and running.

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