python - MQTT paho client Connection timeout error -
i running mqtt mosquitto broker on laptop. trying connect 2 paho mqtt clients it: 1) android phone using java paho , 2) raspberry pi using python paho.
from android connection made perfectly. no problems.
however, raspberry reason can not connect. instead client.connect method blocks , after time receive following:
traceback (most recent call last): file "sensorsclient.py", line 28, in <module> client.connect(mqttserver, 1883) file "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 700, in connect return self.reconnect() file "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 822, in reconnect sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0)) file "/usr/lib/python2.7/socket.py", line 571, in create_connection raise err socket.error: [errno 110] connection timed out
the code connection below:
import paho.mqtt.client mqtt def on_connect(client, userdata, flags, rc): print("connected result code "+str(rc)) client.subscribe("$sys/#") def on_message(client, userdata, msg): print(msg.topic+" "+str(msg.payload)) mqttserver = 'zzz.xxx.ccc.qqq' # public ip of laptop client = mqtt.client("", true, none, mqtt.mqttv31) client.on_connect = on_connect client.on_message = on_message client.connect(mqttserver, 1883) client.loop_start()
everythin done within 1 network via wifi. no mobile data. can please explain me why might happen?
Comments
Post a Comment