homebridge-dafang icon indicating copy to clipboard operation
homebridge-dafang copied to clipboard

Error: Connection refused: Not authorized

Open klzny opened this issue 5 years ago • 4 comments

Hello,

I am getting stuck with error message as follows:

Error: Connection refused: Not authorized at MqttClient._handleConnack (/usr/lib/node_modules/mqtt/lib/client.js:920:15) at MqttClient._handlePacket (/usr/lib/node_modules/mqtt/lib/client.js:350:12) at work (/usr/lib/node_modules/mqtt/lib/client.js:292:12) at Writable.writable._write (/usr/lib/node_modules/mqtt/lib/client.js:302:5) at doWrite (/usr/lib/node_modules/readable-stream/lib/_stream_writable.js:428:64) at writeOrBuffer (/usr/lib/node_modules/readable-stream/lib/_stream_writable.js:417:5) at Writable.write (/usr/lib/node_modules/readable-stream/lib/_stream_writable.js:334:11) at Socket.ondata (_stream_readable.js:693:20) at Socket.emit (events.js:189:13) at addChunk (_stream_readable.js:288:12) at readableAddChunk (_stream_readable.js:269:11) at Socket.Readable.push (_stream_readable.js:224:10) at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:145:17)

Tried already with two different mqtt servers, and the outcome is still the same. Would you have any idea, what do I do wrong?

Xiaomi Xiaofang cam, tried mqtt in Homebridge (RPi) and on Synology NAS,

mqtt.conf:

Options for mosquitto_sub & mosquitto_pub

USER="homebridge" PASS="homebridge" HOST=10.10.0.10 PORT=1883

config.json: { "platform": "Dafang", "mqtt": { "hostBroker": false, "port": 1883, "host": "10.10.0.10", "debug": true }, "cameras":

klzny avatar Feb 11 '20 14:02 klzny

So you have to edit the client.js file (for me it is here: /usr/local/lib/node_modules/homebridge-dafang/node_modules/mqtt/lib/client.js). Find the Section:

var defaultConnectOptions = { keepalive: 60, reschedulePings: true, protocolId: 'MQTT', protocolVersion: 4, reconnectPeriod: 1000, connectTimeout: 30 * 1000, clean: true, resubscribe: true }

And add the authentication stuff like this: var defaultConnectOptions = { host: 'ip.to.your.mqtt.server', port: 1883, username: 'XXX', password: 'XXX', keepalive: 60, reschedulePings: true, protocolId: 'MQTT', protocolVersion: 4, reconnectPeriod: 1000, connectTimeout: 30 * 1000, clean: true, resubscribe: true }

Hope this helps!

Best

se_dony

sedony23 avatar Mar 08 '20 15:03 sedony23

Hi thanks for your help.

Meanwhile I have sorted it in kind of different way. It seems the bistro I was using was at fault as. After doing clean install of raspian/homebridge everything works ok.

Well, kind of. I came across another issue. When I was testing the setup everything was working OK, however after moving it to 'main' homebridge - I am not longer able to add camera. Homebridge does not see it no matter what I try. Dafang plugin works good. I can control the camera (turn night vision on/off, take picture record video - motion sensor works too), there is just no way to add camera. It does not work via homebridge-camera-ffmpeg either.

klzny avatar Mar 13 '20 07:03 klzny

Same issue here. There's nowhere in the homebridge-dafang configuration for adding the username/password for the mosquitto server. This should presumably be in the "mqtt:" section of the plugin configuration. I tried adding it to client.js as sedony23 suggested, but that didn't work. I switched to homebridge-dafang-mqtt-republish in conjunction with homebridge-camera-ffmpeg, and that is working perfectly. So it's not a problem with my MQTT server.

jlg89 avatar Jul 30 '20 16:07 jlg89

The easiest solution is to leave "allow_anonymous true" in the mosquitto config, and also create a password file, so that both authenticated and anonymous connections are handled.

jlg89 avatar Sep 22 '20 21:09 jlg89