eschava / broadlink-mqtt

MQTT client to control BroadLink devices
MIT License
222 stars 60 forks source link

socket.error: [Errno 111] Connection refused paho-mqtt #53

Closed sergge1 closed 4 years ago

sergge1 commented 4 years ago

Privetstvuyu, Evgheniy!

Have tho following issue:

I have an mqtt-broker (Eclipse-mosquitto) and mqtt-client (paho-mqtt) installed at the same box, which is Raspberry Pi 3 B+.

Current behavior: The client paho-mqtt ends with socket.error no.111. if my broker is unreachable (just did not started yet prior to the client).

Expected behavior: Client should make attempts to reconnect until the broker not become active/reachable.

I have seen the similar issue at #38 but did not understood the solution yet.

  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1071, in reconnect
    sock = self._create_socket_connection()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 3522, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python2.7/socket.py", line 575, in create_connection
    raise err
socket.error: [Errno 111] Connection refused
eschava commented 4 years ago

I understand it looks natural that client should keep trying to reconnect to MQTT broker but usually, MQTT broker is run as a service and started by system, before user apps

Could you please describe why in your case MQTT broker could be started after the broadlink-mqtt?

sergge1 commented 4 years ago

mqtt-broker is run as a docker-container. It's official eclipse-mosquito docker container.

I am stopping and starting again container frequently now: for updates, issues tracking with other clients etc. I want to understood the root of that error, as I think the re-connection by paho-mqtt should be done instead of the current behaviour when the client just stops in case broker is not reachable at the moment.