Can I ask for a link or process on how to use Node Red and MQTT

I'm a beginner with Node Red and MQTT, but I've made some good strides. I have two raspberry pis that I downloaded MQTT and Node Red on.

I have simple Nodes that are currently sending the recurring outputs from my only Python code from my first Raspberry Pi to the debug tab. That's how far I've gotten so far because I didn't want to mess up anything else after so many attempts.

What I want to do is wirelessly send that data to my other Raspberry Pi via MQTT for it to receive the values. There's a final step of using that information for serial communication, but I can attempt this later.

Can I ask for some steps that I should do to accomplish this or a link to reference? I've researched and I can't find anything for two Raspberry Pis.

You need an MQTT broker.
If your two Pies are connected to the same Local Area Network, a good choice is to run Mosquitto on one of them.
There is a good installation guide here: https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/

If your router allows this, reserve the IP address for this Pi so it never changes.
Use this IP address in the configuration of Node-red's MQTT nodes.
For testing, use topic "test" in MQTT-out on one Pi and MQTT-in on the other.
Inject some data to MQTT-out ("publish" it) and it will arrive at any MQTT-in ("subscribed" to the topic) node on the other Pi.

The only complication is if the Pies are connected to different networks. In that case you probably need to use a cloud based MQTT broker such as Hivemq.

Probably because MQTT doesn't care what devices are using it. It makes no difference if you are exchanging data between PCs, Linux, microcontrollers or mainframes.

There are a couple of deficiencies in that tutorial.
First, in item 2 it should be
sudo apt update && sudo apt full-upgrade
Secondly in the section on allowing remote access (which @Ceowens will need to do) note that at the top of the file /etc/mosquitto/mosquitto.conf it states
# Place your local configuration in /etc/mosquitto/conf.d/
One should not modify mosquitto.conf itself otherwise a future update may overwrite it. One should instead create a file in the conf.d directory. I make a file /etc/mosquitto/conf.d/mossy.conf and in that put

listener 1883
allow_anonymous true

as suggested in the tutorial. In addition I put there

log_timestamp true
log_timestamp_format %Y-%m-%d %H:%M:%S

which tells it to put human readable timestamps in the log file, in case you need to look at the log, which is in /var/log/mosquitto/mosquitto.log

1 Like

Thank you both for the help, but I am still having a bit of trouble. This may be because I'm on my college wifi, but I wanted to see if I'm doing this right. So on my first Raspberry Pi, I have:

moquitto_sub -h localhost - v -t test_channel

And on my second one, I did hostname -I, got the IP address of my pi, and did:

moquitto_pub -h 172.#.#.# -t test_channel - m "Hello From Other Pi"

I don't see an output on my first Pi. Did I do something wrong in the terminal?

Did you restart mosquito? Reboot to make sure.

Can you ping between the two Pis?

What do you see in the mosquitto log file when you try to connect? /var/log/mosquitto/mosquitto.log

I don't use mosquitto_pub and mosquitto_sub but I don't like the space between "-" & "v" and "-" & "m", and you have consistently misspelled mosquitto. Linux commands do not have autocorrect built in.

So your first Pi is your mosquitto broker...

But that suggests you are trying to use the IP address of your second Pi as the broker. You need to use the IP address of your broker.