sahilchaddha / homebridge-dafang

Homebridge Plugin for Xiaomi Dafang / Wyze Cam IP Camera => Hey Siri, Start Video Recording
MIT License
204 stars 34 forks source link

MQTT doesn‘t work with authentification #34

Closed ScharV closed 5 years ago

ScharV commented 5 years ago

Yeasterday i changed from Plugin Hosting mqtt to mosquitto and it worked fine. Today i edited mosquitto to User authentification and changed my Camera mqtt settings. The Problem i have is that the Plugin always says that there is no authentification and homebridge crashes. If i edit mosquitto to anonymus true the Plugin works but the mqtt Connection with the Camera Not. It makes no difference if the camera has set User and password or not. Streaming works fine but the Switches don‘t....through my log i can See that homebridge is sending mqtt commands

ScharV commented 5 years ago

Found out the Problem and solved it with editing client.js file.

conradhagemans commented 4 years ago

Hi. I am running into the same problem. What did you change in the client.js file? I can see the text "Bad username or password". How do you enter the username/password in the config.json"

        "mqtt": {
       "hostBroker": false,
       "username":"myusername",
       "password":"mypassword",
       "port": 1883,
       "host": "192.168.2.222",
       "debug": true
      },
sedony23 commented 4 years ago

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