0

I have a remote server running mosquitto. I can connect to this server and exchange messages using mosquitto_pub and mosquitto_sub. If i try the same using some python with paho.mqtt.client I get no connection. My script keeps running but the on_connection hook is never called.. The same scripts however work flawlessly with my local mosquitto server.

What could possibly be the reason for the connection problems? How can I get some more feedback on what's happening? Any suggestions?

EDIT: I added a minimal code example

import paho.mqtt.client as mqtt


def on_connect(client, userdata, flags, rc):
    print("Yeeha")
    client.subscribe("botgrid/init", qos=2)

def on_message(client, userdata, msg):
    print(msg.payload)

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost")
print("Waiting for connection...")
client.loop_forever()

EDIT 2: While playing around, I noted that replacing "localhost" with "test.mosquitto.org" resulted in OSError: [Errno 101] Network is unreachable although I have no problems connecting to it via mosquitto_sub

Daniel
  • 140
  • 2
  • 8
  • Can you post your (or a section of) script so we can have a look? – hardillb Nov 03 '14 at 22:46
  • What version of mosquitto? I bet you're on 0.15 or 1.2.x. – ralight Nov 03 '14 at 23:03
  • @ralight I just now installed mosquitto version 1.3.5 (build date 2014-10-08 22:31:34+0000) in hope that this solved the issue. However, it didn't. – Daniel Nov 03 '14 at 23:29
  • That code snippet works fine for me with localhost, a broker on my local net and test.mosquitto.org. My only thought about the Network unreachable error is that it's reachable via IPv6 and you only have IPv4. Have you tried using IP addresses instead of names? – hardillb Nov 03 '14 at 23:50
  • Yes, I have. Again, 127.0.0.1 results in a yeeha, the remote IP does not. Is there any way I can get more information out of the client that helps me closing in on the cause? – Daniel Nov 04 '14 at 00:20
  • I can't see any trace in the python code, best suggestion at this point is use something like wireshark to capture all the traffic on port 1883 – hardillb Nov 04 '14 at 15:48
  • Thank you for your time spent!I was hoping to avoid that, but if all else fails... – Daniel Nov 04 '14 at 21:16
  • Just use `mosquitto -v` to see verbose info. If `Sending CONNACK to ...` is displayed, then the client maybe not receiving traffic data (something wrong with the `client.loopforever()`), or the server is not running properly. – Joshz Nov 03 '15 at 08:09

1 Answers1

0

Does this code produce the same problem? This is probably the equivalent to the code at the point that it is failing.

import socket

sock = socket.create_connection(("test.mosquitto.org", 1883))
ralight
  • 11,033
  • 3
  • 49
  • 59