Open ytimenkov opened 2 weeks ago
same symptoms for me as well but using IPv4
Hi, I have the same Problem
[2024-05-05 23:05:09] info: z2m: Connecting to MQTT server at http://192.168.2.144:1883 [2024-05-05 23:05:09] error: z2m: MQTT error: connect ECONNREFUSED / [2024-05-05 23:05:09] error: z2m: MQTT failed to connect, exiting... [2024-05-05 23:05:09] info: z2m: Stopping zigbee-herdsman... [2024-05-05 23:05:10] error: z2m: MQTT error: connect ECONNREFUSED / [2024-05-05 23:05:11] error: z2m: MQTT error: connect ECONNREFUSED / [2024-05-05 23:05:12] error: z2m: MQTT error: connect ECONNREFUSED / [2024-05-05 23:05:13] error: z2m: MQTT error: connect ECONNREFUSED / [2024-05-05 23:05:14] error: z2m: MQTT error: connect ECONNREFUSED / [2024-05-05 23:05:15] error: z2m: MQTT error: connect ECONNREFUSED / [2024-05-05 23:05:16] error: z2m: MQTT error: connect ECONNREFUSED /
@SoSv73 you shouldn't use http://
, use mqtt://192.168.2.144:1883
Thanks Koenkk, that was very usefull. Now it works like a charm. Thank you very much
I guess docker networking defaults to IPv6 as I'm having the same issue with the following server url: mqtt://mosquitto:1883
zigbee2mqtt | [2024-05-07 22:11:05] info: z2m: Connecting to MQTT server at http://mosquitto:1883/
zigbee2mqtt | [2024-05-07 22:11:05] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:05] error: z2m: MQTT failed to connect, exiting...
zigbee2mqtt | [2024-05-07 22:11:05] info: z2m: Stopping zigbee-herdsman...
zigbee2mqtt | [2024-05-07 22:11:07] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:08] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:09] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:10] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:11] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:12] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:13] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:14] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:15] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:16] error: z2m: MQTT error: connect ECONNREFUSED /
zigbee2mqtt | [2024-05-07 22:11:17] error: z2m: MQTT error: connect ECONNREFUSED /
After exposing 1883 to 0.0.0.0 and switching the server url to local_ipv4:1883 it works again.
Can you check with the latest dev branch?dev branch
I've just tested the image koenkk/zigbee2mqtt:latest-dev and it works as expected :)
zigbee2mqtt | [2024-05-07 22:31:22] info: z2m: Connecting to MQTT server at mqtt://mosquitto:1883/
mosquitto | 1715113882: New connection from 172.31.0.2:44940 on port 1883.
mosquitto | 1715113882: New client connected from 172.31.0.2:44940 as zigbee (p2, c1, k60, u'z2m_qtt').
zigbee2mqtt | [2024-05-07 22:31:22] info: z2m: Connected to MQTT server
Wonderful, thank you!
So something broke with a recent version of MQTT.js, can you do:
docker exec -it zigbee2mqtt CONTAINER_NAME sh
npm install mqtt@5.5.1
exit
docker restart CONTAINER_NAME
See if it still works, then bump the mqtt
version until it breaks.
I had to apk add npm
to the alpine image even when it's on the Dockerfile
Testing with main image, not latest.
5.5.3 worked, 5.5.4 didn't.
5.5.5 works with a caveat server: 'mqtt://mosquitto:1883/' still gets a connection refused but 'mqtt://mosquitto:1883' works as expected.
Connection error: Error: connect ECONNREFUSED /
at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '/'
}
Given that I haven't seen documentation with the trailing slash, I think it's a just me issue.
I used this tiny script that may be handy for someone else:
const mqtt = require("mqtt");
// MQTT broker URL
// const brokerUrl = "mqtt://mosquitto:1883/";
const brokerUrl = "mqtt://mosquitto:1883";
// MQTT broker username and password
const options = {
username: "z2m_qtt",
password: "password"
};
// Connect to the MQTT broker
const client = mqtt.connect(brokerUrl, options);
client.on("connect", () => {
// Subscribe to a topic
client.subscribe("presence", (err) => {
if (!err) {
// Publish a message after successful subscription
client.publish("presence", "Hello mqtt");
} else {
console.error("Subscription error:", err);
}
});
});
client.on("message", (topic, message) => {
// Display received message
console.log(message.toString());
// Close the client connection
client.end();
});
// Handle connection errors
client.on("error", (error) => {
console.error("Connection error:", error);
});
Edit. I'm closing the PR, I've just noticed the regression from 5.5.5 to 5.5.0 and I'm not aware of why but you must know something I don't.
So it starts to break from 5.5.4?
Sorry for late reply.
I tried latest-dev
tag and can confirm that it fixes the problem (zigbee2mqtt connects to mosquitto via IPv6)
/app # grep version node_modules/mqtt/package.json
"version": "5.5.0",
I wonder if it is related to https://github.com/mqttjs/MQTT.js/pull/1852 (or corresponding issue?) (based on fuzzy gpt-style text searching for most probable location π).
Digging a bit more I saw that you've downgraded mqtt.js version in dev. Then it makes more sense (I didn't pay attention to the versions and thought that you've bumped to the latest 5.5.5).
I wonder if it is related to mqttjs/MQTT.js#1852 (or corresponding issue?) (based on fuzzy gpt-style text searching for most probable location π).
Given that my error is slightly different it's clearly related, and thinks the address is a socket path or something silly:
z2m: Starting Zigbee2MQTT version 1.37.0 (commit #unknown) z2m: Starting zigbee-herdsman (0.45.0) ... z2m: Connecting to MQTT server at mqtt://[fd0c::4c]:1883 z2m: MQTT error: connect EAFNOSUPPORT / z2m: MQTT failed to connect, exiting...
(EAFNOSUPPORT
presumably occurs when it's hardened under systemd to only allow RestrictAddressFamilies=AF_INET6
)
@ytimenkov does 5.5.5 work for you?
@Koenkk No, it doesn't:
/app # apk add npm
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/aarch64/APKINDEX.tar.gz
(1/1) Installing npm (9.6.6-r0)
Executing busybox-1.36.1-r2.trigger
OK: 77 MiB in 34 packages
/app # ls data/
configuration.yaml coordinator_backup.json database.db
/app # npm install mqtt@5.5.5
changed 1 package, and audited 209 packages in 1m
30 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
/app # node index.js
[2024-05-12T06:02:26+00:00] error: z2m: MQTT error: connect ECONNREFUSED /
[2024-05-12T06:02:26+00:00] error: z2m: MQTT failed to connect, exiting...
[2024-05-12T06:02:27+00:00] error: z2m: MQTT error: connect ECONNREFUSED /
[2024-05-12T06:02:28+00:00] error: z2m: MQTT error: connect ECONNREFUSED /
The latest 1.37.1 works though. Release notes mention it as #605.
What happened?
After updating docker image to 1.37.0 zigbee2mqtt exits after start with:
After switching to ipv4 address, the daemon started.
What did you expect to happen?
No response
How to reproduce it (minimal and precise)
No response
Zigbee2MQTT version
1.37.0 (commit #46f34c8)
Adapter firmware version
not applicable
Adapter
not applicable
Setup
Podman with netavark stack
Debug log