Connecting to MQTT broker in Docker

I’m trying to get a basic Hermes app going but I’m running into some trouble. I have the rhasspy container up and running and I’m also running the time_app.py file to get the current time. Rhasspy works with the wake word and recognizes intents, however, when I run the python file, I can’t connect to the MQTT broker. Here are the logs:

With port 12183:

    python3 examples/time_app.py --port 12183 --host 10.0.2.15 --debug
[DEBUG:2020-11-20 13:28:28,937] HermesApp: Namespace(debug=True, host='10.0.2.15', log_format='[%(levelname)s:%(asctime)s] %(name)s: %(message)s', password=None, port=12183, site_id=None, tls=False, tls_ca_certs=None, tls_cert_reqs='CERT_REQUIRED', tls_certfile=None, tls_ciphers=None, tls_keyfile=None, tls_version=None, username=None)
[DEBUG:2020-11-20 13:28:28,937] asyncio: Using selector: EpollSelector
[DEBUG:2020-11-20 13:28:28,938] HermesApp: Connecting to 10.0.2.15:12183
Traceback (most recent call last):
  File "examples/time_app.py", line 21, in <module>
    app.run()
  File "/home/evan/.local/lib/python3.8/site-packages/rhasspyhermes_app/__init__.py", line 615, in run
    hermes_cli.connect(self.mqtt_client, self.args)
  File "/home/evan/.local/lib/python3.8/site-packages/rhasspyhermes/cli.py", line 91, in connect
    client.connect(args.host, args.port)
  File "/home/evan/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/home/evan/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1071, in reconnect
    sock = self._create_socket_connection()
  File "/home/evan/.local/lib/python3.8/site-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/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/usr/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Port 12101:

python3 examples/time_app.py --port 12101 --host 10.0.2.15 --debug
[DEBUG:2020-11-20 13:28:38,535] HermesApp: Namespace(debug=True, host='10.0.2.15', log_format='[%(levelname)s:%(asctime)s] %(name)s: %(message)s', password=None, port=12101, site_id=None, tls=False, tls_ca_certs=None, tls_cert_reqs='CERT_REQUIRED', tls_certfile=None, tls_ciphers=None, tls_keyfile=None, tls_version=None, username=None)
[DEBUG:2020-11-20 13:28:38,561] asyncio: Using selector: EpollSelector
[DEBUG:2020-11-20 13:28:38,562] HermesApp: Connecting to 10.0.2.15:12101
[DEBUG:2020-11-20 13:28:38,565] asyncio: Using selector: EpollSelector

I don’t get what the problem is, I’ve got it working before on a different laptop with docker, but I’m not sure what’s wrong here. Any ideas?

Are you using an internal or an external mqtt server? I personally have never played around with the internal mqtt server but the port you hand over to the time app has to be the mqtt port rhasspy uses. For me with my external mqtt server it was 1883, 12101 is the port for the web gui as far as I know, and 12183 might be the internal mqtt port, if that is the case, can you connect with an mqtt client to that port (I use MQTT Explorer on windows, but any mqtt client should work to test that), if not, have you actually exposed the port to the outside?

I hope those little snippets of information help somewhat.

Daenara

1 Like

I’m using the internal MQTT server setting, so for me, port 12183 should work right?

Yes, but if Rhasspy is running in the container, you should expose the port too ( -p 12183:12183) and then connect your Rhasspy app to localhost if it’s running on the same machine or the IP address of the machine your Rhasspy container is running on otherwise.

1 Like