MQTT ConnectTimeoutException connection failes

  • Platform information:
    • Hardware: Pentium D
    • OS: Ubuntu, docker
    • Java Runtime Environment:
    • openHAB version: 3

I cannot connect to the mqtt broker. I have this issue regularly, sometimes it magically works.
Everything runs in docker container. I can connect via mqtt explorer and see mosquitto receiving messages. I can also publish messages, but openhab does not receive it.

I installed mosquitto-clients within the openhab container and subscribed to various topics, but cannot see any message/topic from within the openhab container.
io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.103.44:1883

root@c6c82beb77fb:/openhab# mosquitto_sub -h 192.168.103.44 -t "test"

I also made a new mqtt bridge item in openhab, but still have the same error.

The connection to the web works well from the container:

/openhab# wget --spider http://www.google.co.in/
Spider mode enabled. Check if remote file exists.
--2023-10-29 20:38:18--  http://www.google.co.in/
Resolving www.google.co.in (www.google.co.in)... 142.250.186.131, 2a00:1450:4001:82a::2003
Connecting to www.google.co.in (www.google.co.in)|142.250.186.131|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.

Please don’t setup a mosquitto client within the openHAB container.
Docker containers should not be changed like this (at least if you don’t like to maintain your container)
Instead, use the standard docker container and another docker container for mosquitto server.
The openHAB container should be run in host mode to get stuff like avahi running.
What are the ip addresses of both openHAB and mosquitto?

Thank you very much for the hints. I think I was not specific enough here:

  1. mosquitto and openHAB run in different container.
  2. I just installed mosquitto in the openHAB container for testing reasons. I did not know what else to test as
    a) Internet connection is working properly from within the openHAB container
    b) mqtt broker mosquitto is also working properly in the network (confirmed by mqtt explorer).

When I just delete the OpenHAB container (not the volumes) and start it again, I have a fresh system without mosquitto installed into OpenHAB.

openHAB and mosquitto run on the same server with ip 192.168.103.44.
The adresses within docker are:


           "8d85a33fa13c96618723ceb66ea2d108de5448938ee0a202a6bb681cffadfa35": {
                "Name": "openhab",
                "EndpointID": "be07bfb8d3d9e3bf1e239537592b84910e9c2a08caad73e0ef7878f0c0aaf5ea",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "b69ec42f7c407a636e4406dd3178d2cac5367c19f79d9af7806cf888a4dacabf": {
                "Name": "nc_mariadb",
                "EndpointID": "9f2e322fff7d3ed8ee0d24fa96ba80c561c9962bbc1bb7556ae82dd50a23f7f3",
                "MacAddress": "02:42:ac:12:00:05",
                "IPv4Address": "172.18.0.5/16",
                "IPv6Address": ""
            },
            "bb96100400faf382d521794474af4ab139672b3960ca172d639ff63c8d5a935b": {
                "Name": "mosquitto",
                "EndpointID": "0a8e7232c34f89b39b416308eee81370aafb94a1b7d6caccf28f5ec38e1440f8",
                "MacAddress": "02:42:ac:12:00:07",
                "IPv4Address": "172.18.0.7/16",
                "IPv6Address": ""
            },

Its really annoying. I just found out that when you put openhab and mosquitto in the same network, openhab can access the mqtt server with the adress from the docker network (here: 172.18.0.7). But it cannot access from the “official” server port 192.168.103.44:1883.

Is that a bug?

If it is a bug, it’s going to be a bug in Docker. As far as openHAB and Mosquitto are concerned there isn’t such a thing as a container. They are just running on a machine from their perspective.

It’s more likely a configuration issue.

  • Is Mosquitto configured to listen on all networks or just the 192.168 network?
  • You’ve forwarded the port on the Mosquitto container?
  • You are using a different client ID for openHAB, MQTT Explorer, and any other MQTT client connected to the broker?