Hi,
I thought it might help someone to flag a slightly obscure issue with Mosquitto running as an add-on.
After several hours of debug, head-scratching and reading docs, forum posts, etc, I’ve reported an issue that the Mosquitto MQTT broker integration works with IPv4, fails with IPv6.
If you are seeing lots of Socket error on client <unknown>, disconnecting.
errors in the Mosquitto add-in log file, it may be worth checking if you are connecting via IPv4 or IPv6 (hint: set clients to use the server IPv4 address rather than a hostname).
In the UK, the ISP BT provides routers which now prefer IPv6 (good!) via both DHCP and internal private DNS - my mistake was to configure my Tasmota 11 clients with an internal hostname (like tasmota-name.home
, rather than an explocit IPv4 address (like 192.168.1.10
). The router resolved the name to an IPv6 address of the Home Assistant server, which rejected the connection.
This was checked by installing mosquitto_sub
command-line MQTT client tools on a Linux client and also using telnet
to connect to the broker .
This may be a bit of an unusual error due to a router preferring IPv6 - issues with authentication (don’t use homeassitant
as a username, create a separate User such as tasmota
), or wrong IPv4 network addresses seem a lot more common.
Details are in the bug report, but to help forum searches…
Steps to reproduce
IPv6 fails - Socket error
- Connect from a test laptop to HASS running mosquitto using the command line tool
mosquitto_sub
. - The initial config used a hostname for the HASS server, which the router DNS resolved to an IPv6 record.
- Socket error in the Mosquitto log, no connection on the client
# Fails
mosquitto_sub -d -i "monitor" -h homeassistant.home --username 'tasmota' --pw 'secret' -v -t '#'
1650115240: New connection from 192.168.1.10 on port 1883.
1650115240: Socket error on client <unknown>, disconnecting.
1650115240: New connection from 192.168.1.20 on port 1883.
1650115240: Socket error on client <unknown>, disconnecting.
IPv4 works
- Change the
mosquitto_sub
command line from a hostname (resolved by the router to IPv6) to the explicit IPv4 address of the HASS server. -
mosquitto_sub
connects immediately without issue.
# works
mosquitto_sub -d -i "monitor" -h 192.168.1.50 --username 'tasmota' --pw 'secret' -v -t '#'
Client monitor sending CONNECT
Client monitor received CONNACK (0)
Client monitor sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0, Options: 0x00)
Client monitor received SUBACK
Subscribed (mid: 1): 0
Network diagnostic test
Using telnet
to connect to the HASS server port used for MQTT is a simple way to check networking.
Telnet IPv6 test - FAILS
Does not connect:
$ telnet homeassistant.home 1883
Trying 2a00:[IPv6 address removed]...
^C
Telnet IPv4 Test - WORKS
Connects immediately (the -4
switch forces IPv4, as would using your server address like 192.168.1.50):
$ telnet -4 homeassistant.home 1883
Trying 192.168.1.50...
Connected to homeassistant.home.
Escape character is '^]'.
Hope this helps,
James