Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Connection refused: Not authorized #50

Open
klzny opened this issue Feb 11, 2020 · 4 comments
Open

Error: Connection refused: Not authorized #50

klzny opened this issue Feb 11, 2020 · 4 comments

Comments

@klzny
Copy link

klzny commented Feb 11, 2020

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":

@sedony23
Copy link

sedony23 commented Mar 8, 2020

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

@klzny
Copy link
Author

klzny commented Mar 13, 2020

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.

@jlg89
Copy link

jlg89 commented Jul 30, 2020

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
Copy link

jlg89 commented Sep 22, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants