SAIC-iSmart-API / saic-python-mqtt-gateway

A service that queries the data from an MG iSMART account and publishes the data over MQTT and to other sources
MIT License
71 stars 21 forks source link

Connection Refused to Mosquitto #246

Closed eximo84 closed 4 months ago

eximo84 commented 4 months ago

So I'm running mosquitto mqtt in docker. Other containers such as zigbee2mqtt connect fine but I cannot get this container to connect.

Log below. The container stops instantly so I can't even troubleshoot from the container.

Traceback (most recent call last):
  File "/usr/src/app/./mqtt_gateway.py", line 941, in <module>
    asyncio.run(mqtt_gateway.run(), debug=debug_log_enabled())
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/src/app/./mqtt_gateway.py", line 506, in run
    await self.publisher.connect()
  File "/usr/src/app/publisher/mqtt_publisher.py", line 86, in connect
    await self.client.connect(host=self.host, port=self.port, version=gmqtt.constants.MQTTv311, ssl=ssl_context)
  File "/usr/local/lib/python3.12/site-packages/gmqtt/client.py", line 225, in connect
    self._connection = await self._create_connection(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gmqtt/client.py", line 241, in _create_connection
    connection = await MQTTConnection.create_connection(host, port, ssl, clean_session, keepalive, logger=self._logger)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gmqtt/mqtt/connection.py", line 27, in create_connection
    transport, protocol = await loop.create_connection(MQTTProtocol, host, port, ssl=ssl)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1122, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1104, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1007, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 651, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 691, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.10', 1833)
2024-06-15 11:59:42,942 [ ERROR  ] Task was destroyed but it is pending!
task: <Task pending name='Task-1' coro=<Client._resend_qos_messages() running at /usr/local/lib/python3.12/site-packages/gmqtt/client.py:176>> - asyncio
sys:1: RuntimeWarning: coroutine 'Client._resend_qos_messages' was never awaited
eximo84 commented 4 months ago
2024-06-15 18:50:57,961 [  INFO  ] [CONNECTION MADE] - gmqtt.mqtt.protocol

2024-06-15 18:50:58,062 [  INFO  ] [CONN CLOSE NORMALLY] - gmqtt.mqtt.protocol

2024-06-15 18:50:58,063 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol

So if i switch to websockets i get this. The mosquitto log doesnt show any attempt for connection from the SAIC gateway container :/

eximo84 commented 4 months ago

So managed to get connected. Seems I had to use a username and password despite anonymous being enabled on my broker.