Great! I got the Broker running on the Ubuntu machine by following these instructions:
Mosquitto is a lightweight open source message broker that Implements MQTT versions 3.1 and 3.1.1.
www.steves-internet-guide.com
Then, I installed two simple sub-pub scripts from here on the Pi Zero:
Learn to use MQTT in Python with Paho Client, the easy way! Our step-by-step tutorial will have you up and running in no time with this popular IoT protocol.
www.emqx.com
Using the above two scripts as is (public broker) works as described. But changing the broker address to my local Ubuntu machine address, i get connection refused errors running the same scripts above:
pi@raspberrypi:~ $ python3 sub.py
Traceback (most recent call last):
File "/home/pi/sub.py", line 46, in <module>
run()
File "/home/pi/sub.py", line 40, in run
client = connect_mqtt()
File "/home/pi/sub.py", line 27, in connect_mqtt
client.connect(broker, port)
File "/home/pi/.local/lib/python3.9/site-packages/paho/mqtt/client.py", line 914, in connect
return self.reconnect()
File "/home/pi/.local/lib/python3.9/site-packages/paho/mqtt/client.py", line 1044, in reconnect
sock = self._create_socket_connection()
File "/home/pi/.local/lib/python3.9/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
File "/usr/lib/python3.9/socket.py", line 843, in create_connection
raise err
File "/usr/lib/python3.9/socket.py", line 831, in create_connection
sock.connect(sa)
socket.timeout: timed out
both devices, I can ssh to eachther without a password, except I need to hostname include it, for examaple
$ssh hostname@ip
no password is required to ssh between computes.
For some reason, I cannot stop or restart the broker on my Ubunut machine, I don;t know if this part of my connection issues
sudo service mosquitto stop
sudo systemctl stop mosquitto.service
When I try to turn it back on via this:
mosquitto -v #start in verbose mode
it says that the port 1883 is alreadty in use, so its running I guess, but it might be hung?
It works once, where when I ran the above script, it says "Conneted to Broker!!!" but after that, it starting giving me connection refused issues, even runnint the script with sudo
It shouldn't be this hard to run a local broker? is there some mosquitto options I have to selected in the config file?