Hello I would like to configure paho mqtt but I am having trouble to get it to work properly. I am trying to connect my raspberry to external server where broker is up and running. Port and IP are fine, I can publish from Terminal to exteral server, so this also means firewall is not a problem.

import paho.mqtt.client as mqtt
broker = "IP_of_exetrnal server"

client = mqtt.Client()
client.connect(broker, 1883, 60)
client.publish("MyTopic/", "Test message")

The error stack looks like this. Can you help me get rid of it?

Traceback (most recent call last):
File "Agregator.py", line 20, in <module>
File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 839, 
in connect
return self.reconnect()
File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 
1009, in reconnect
return self._send_connect(self._keepalive, self._clean_session)
File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 
2388, in _send_connect
return self._packet_queue(command, packet, 0, 0)
File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 
2535, in _packet_queue
BrokenPipeError: [Errno 32] Broken pipe
  • 1
    Is your network connected? Can you ping "ip_of_external_server"? Can you traceroute to that server? Can you publish on there with mosquitto_pub -h ip_of_external_server -t 'MyTopic' -m 'Test message'? BTW, ending a topic with a slash / is invalid so the remote system may be rejecting your attempt to publish a message. – Dougie Jan 8 at 23:24
  • 1
    Do you have the correct port? The stack trace implies you are using port 8883 instead of 1883. 8883 is the default MQTT TLS connection which usually requires certificates to be setup. – blt Jan 9 at 2:03
  • Yes I have network connection. As stated higher I am able to perform publish from Terminal with structure mosquitto_pub -h ip_of_external_server -t 'MyTopic' -m 'Test message'?. So I am sure of port and IP address. I have checked topic ending, but unfortunately thats not the case. Also I have checked other ports to replace 8883, but didnt do the work. – Mzw Jan 9 at 21:01
  • I'd run a tcpdump or wireshark on the good working connection then run the same with your python program. I'd also try mosquitto_sub on port 8883 with the certificate stuff. – Dougie Jan 10 at 0:00
  • I found this link link so it might be the issue. I am inserting IP address in my code and it seems its not supported. – Mzw Jan 12 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.