0

Setup: I have a Linux Laptop (Ubuntu Mate 20.04) running a Mosquitto broker and I am trying to subscribe from a raspberry pi which is inside my home network. I can publish and subscribe to the broker from my laptop, but not from the outside (other devices in my home network).

I have a config file under /etc/mosquitto/conf.d/ including: listener 1883 allow_anonymous true as it is recommended here https://stackoverflow.com/a/65278769.

Still it is not working and when I subscribe to a topic i am not receiving any messages. There is no error either. I appreciate any ideas how I can fix that.

The server status: enter image description here

To publish I use the command mosquitto_pub -h localhost -t "test/message" -m "message here" and for subscribing mosquitto_sub -h localhost -t "test/message" and it is working inside the Linux Laptop itself as you can see here: enter image description here

When I try to subscribe from the raspberry pi: mosquitto_sub -h 192.168.1.103 -t "test/message" Error: No route to host

These are the devices in my network with IPs: enter image description here

Enabling the firewall and allowing port 1883 for TCP is not working. Same with disabling firewall completely.

enter image description here

Holger
  • 74
  • 1
  • 9
  • 1
    Hi @Holger - please edit your post to include your entire Mosquito configuration, not just a few lines of it. Also please include the command or code you're trying to use to subscribe, including the IP address (it's a private IP and is not going to identify anything). Are you running a firewall on your Linux laptop? – romkey Jun 30 '22 at 17:34
  • 1
    Your RasPi can't even get to your laptop. Try `ping 192.168.1.103` from your RasPi. And `hostname -I` on your RasPi. – Mark Setchell Jun 30 '22 at 18:08
  • @romkey when I do `sudo firewall-cmd --state` in terminal I get `running` so the firewall is active – Holger Jun 30 '22 at 18:10
  • @MarkSetchell I can ping from both sides. From laptop to the raspberry and the otherway around. – Holger Jun 30 '22 at 18:13
  • @MarkSetchell `hostname -I` gives me `169.254.106.128 192.168.1.106 ` as a return. not sure what the first IP means. – Holger Jun 30 '22 at 18:20
  • Then you're going to need to permit access to Mosquitto in your firewall in order for anything outside of your laptop to talk to it. Also as @MarkSetchell pointed out you need to resolve the issue that's preventing your raspberry pi from talking to your laptop. If you can't get the Pi to ssh or ping your laptop, you need to fix that before MQTT will even possibly work. – romkey Jun 30 '22 at 19:58
  • @romkey but i can ping from both sides with no problem. and ssh works fine. – Holger Jun 30 '22 at 20:22
  • Yes, but that's because the firewall is explictly allowing ICMP (ping) and port 22 (SSH). You need to open port 1883 (MQTT) – hardillb Jun 30 '22 at 23:00
  • @hardillb when the firewall is inactive it is not working. when i start it and allow port 1883 it is not working. so that is not changing anything. but still thx. – Holger Jun 30 '22 at 23:49
  • Have you got a line like this in your config file `listener 1883 0.0.0.0` ? – Mark Setchell Jul 01 '22 at 06:42
  • Just a guess: your first IP address on raspberry could be for another network interface and that interface is used by the client by default. Try to use option "-A" for mosquito_sub with 192.168.1.106 – Artem Suprunov Jul 02 '22 at 23:39

0 Answers0