sgupta999 / mqtt-bridge-smartthings

MQTT Bridge To SmartThings [MBS]
MIT License
27 stars 15 forks source link

1.03 first comments... its not working!!! #8

Closed rhamblen closed 4 years ago

rhamblen commented 4 years ago

Did an npm to install the new package. Didnt use the docker, just updated everyting! Firstly wasnt expecting a config directory... threw me on first run when I had all your devices running and then it crashed. Then when I modified the files in the config directory, I then had problem where your devices still existed as they were in last state file! and things still crashed. Im looking at why it is crashing now... just saying 'thow er;' after I connected to the MQTT server @ ip address! events.js:187 being the location.

Will find out more and let you know... also what's the MSB V2... I get an error if I use it, but think it is for same reason.

rhamblen commented 4 years ago

so I think Ive fixed all the errors... the config file expects a different setup for 'host', to previously and as your example given.
Previously host: with no port; example host: "mqtt://:" now it appears it wants host: :

which is interesting. Having fixed things so it reads just my config file, and that was fixed by removing the state files! I now have it reading my devices BUT no actual subscriptions requested from smartapp.

Looking into that now!

sgupta999 commented 4 years ago

Just use the same config file that you had before that should not change - I had added the mqtt to make it clearer if you were using a local mqtt sever - if someone was using a cloud server it would be a full host url etc.

if u deleted state files you need to go into smartpp on phone, go to settings and hit save there to resubscribe everything

without state files its like a fresh starts.

Just use your same old config and device files and hit save in mobile app in smartapp settings that should work

sgupta999 commented 4 years ago

The docker file setup makes it a lot easier for folks to install - especially the combined mosquitto and mbs server install - but npm should work too without too much trouble.

For your setup all you should have had to do is move the log and data folders to a the 'config' directory. copy the config and device also in the 'config' directory, there to resume as before

let me know if that does not work.

sgupta999 commented 4 years ago

I will have to improve error handling so the sever just does not crash under any situation. I am working on error log having more details and also having the option to print error messages on console in debug mode - also have ideas about improving performance.

Improvement coming - did not want to do a big structural change like this in file structure but docker really limits how you expose user editable content to host machine -

i think it makes it clear too

rhamblen commented 4 years ago

i get your point about docker, but I just didnt see the need to go back to square 1! Anyway, I have used the same config and devices file now, but initially it didnt work. the real problem is that it isnt talking to ST at all... nothing is going either way... Because it isnt talking to ST, Im not subscribing to anything in MQTT! I was going to write something to force the MQTT connection, just so I can confirm I get traffic. BUT Im looking to see what is causing the problem first.

Most likely it is me! but I cant see what is going wrong when everything is the same as before and I've done the checks with the app and the device handlers/devices

sgupta999 commented 4 years ago

are you getting to listening on port 8080? If ST is not talking to server make sure the birdge is configure ok Nothing changed on ip address mac for server running mbs?

Ifyou can post your log file or error log i can probably zero in pretty fast.

sgupta999 commented 4 years ago

are you up and running

rhamblen commented 4 years ago

simple answer 'no' but I cant delete the MQTT bridge device or app - leaving 12 hours and retrying in the morning was going to rebuild everything first

sgupta999 commented 4 years ago

I am having similar issue with ST for some other apps - u shouldn’t have to delete the app/bridge anyway - the changes were on the server side

sgupta999 commented 4 years ago

Try going to home —> hub —> smartapps—> uninstall in IDE that’s the only thing that sometimes works for me

rhamblen commented 4 years ago

everything deleted, will try tonight to rebuild everything in the IDE. When ST gets in a mess, its not unusual to have to wait 12-24 hours before you can delete things. Had it in the past. agree re changes but was going back to basics in case there was something.
MQTT bridge was trying to send messages but the mbs-server wasnt communicating at all. it was unable to see any subscription requests from the smartapp. - no errors. Obviously with no subscriptions requested, it then doesnt communicate with mosquitto!

sgupta999 commented 4 years ago

Just FYI I have had this happen under the following conditions:

  1. One of either ip, port, or MAC address of the machine running MBS server in bridge is wrong
  2. Using docker, windows did not automatically prompt me to allow firewall access to docker container so was getting blocked without any specific error messages. That is why that special firewall rule for docker in Windows

I know you are using Ubuntu and probably nothing has changed in the environment but make sure firewall is not the issue

  1. I deleted the bridge to re-add to make sure it was getting the properties right and then forgot to select it again under the smartapp config
rhamblen commented 4 years ago

I completly removed the whole thing and started again... fresh build! few things I noticed this time around...

  1. in the ST device handler, set the default value for the port number. Its just easier if you do this. I initially set it as 1883 for the broker and then realised it was 8080 for the bridge.

  2. You have done something very different in mbs-server! basically it isnt talking to my ST at all! I (like first time around) am gatting your save state with your devices because it isnt seeing any request from my ST app.

I just sits at the 'connecting to MQTT at 192.168.1.108:1883' doing nothing more. so it gets to the connectToMQTT function @603.

What did occur to me is the difference in the host parameter in config.yml previously I needed to put in only no port number you put in mqtt://: and this didnt work for me. I found I needed to put in :

so there is something funny happening here!

I've not got to testing docker yet, but thats because I trying to do 10things at once which are important to me! including wiring up an new network point and outside light!!! sorry!

anyway... enjoy thanksgiving and I'll let you know how I get on.

sgupta999 commented 4 years ago

no you don't need to specif the port 1883 - that will not work. If I remember that was the problem last time

in the host just put mqtt://192.168.1.xxxx

if you are seeing this MQTT at 192.168.1.108:1883 that will not work it needs to read as above. port 8080 in config file for server and in bridge

port 1883 nowhere

rhamblen commented 4 years ago

but without it you get a throw error

2019-11-27 11:28:58 AM info: Connecting to MQTT at mqtt://192.168.1.108 2019-11-27 11:28:58 AM info: end of connectToMQTT events.js:187 throw er; // Unhandled 'error' event ^

Error: Connection refused: Not authorized at MqttClient._handleConnack (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/client.js:1076:15) at MqttClient._handlePacket (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/client.js:365:12) at work (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/client.js:283:12) at Writable.writable._write (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/client.js:294:5) at doWrite (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/readable-stream/lib/_stream_writable.js:428:64) at writeOrBuffer (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/readable-stream/lib/_stream_writable.js:417:5) at Writable.write (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/readable-stream/lib/_stream_writable.js:334:11) at Socket.ondata (_stream_readable.js:747:22) at Socket.emit (events.js:210:5) at addChunk (_stream_readable.js:326:12) Emitted 'error' event on MqttClient instance at: at MqttClient._handleConnack (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/client.js:1078:10) at MqttClient._handlePacket (/usr/lib/node_modules/mqtt-bridge-smartthings/node_modules/mqtt/lib/client.js:365:12) [... lines matching original stack trace ...] at addChunk (_stream_readable.js:326:12) { code: 5 }

rhamblen commented 4 years ago

Its easier to grab the console output than to try to get the log file! I added some lines so I can trace where we are in the code. so you will see some extra debug lines.

output.txt

sgupta999 commented 4 years ago

IF you check your original first issue that you created and closed you had a similar issue - could it be the same - something to do with your mosquitto setup?

I know that with port if will definitely not work. This may be specific to your mosquitto setup or environment

the only change in the server from your previous set up is the change i the location of the config directory

rhamblen commented 4 years ago

Jes' after all that it was a typo in the username... I had capitalised the first letter. (because thats what I normally do!) I wonder if we can catch this and rather than crash we give an error back which says invalid un/pwd. Back to testing again.

(hangs head in shame and embaracement for a noob error!)

sgupta999 commented 4 years ago

That’s MQTT package error handling nothing I can do there

Although the error message does say access denied or something to that effect so that should be a clue

Sent from my iPhone

On Nov 27, 2019, at 12:39 PM, rhamblen notifications@github.com wrote:

 Jes' after all that it was a typo in the username... I had capitalised the first letter. (because thats what I normally do!) I wonder if we can catch this and rather than crash we give an error back which says invalid un/pwd. Back to testing again.

(hangs head in shame and embaracement for a noob error!)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.