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

Connection to MQTT broker failed #38

Open
wewa00 opened this issue Jan 3, 2021 · 11 comments
Open

Connection to MQTT broker failed #38

wewa00 opened this issue Jan 3, 2021 · 11 comments

Comments

@wewa00
Copy link
Contributor

wewa00 commented Jan 3, 2021

Hello,
Reacticz is not able to connect to the MQTT broker.
But I do not understand why. The url and the data used for authentication are valid. I can use the same data and connect via mqtt-spy via websockets to the MQTT broker.
Mosquitto MQTT v3.1/v3.1.1 Broker is used as MQTT broker.

Any idea what is failing here?

Best regards
wewa

@secator76
Copy link

secator76 commented Jan 7, 2021

Hello,
same problem. I think, it's since the Mosquitto 2.0.4 update.

with this command: sudo tail -f /var/log/mosquitto/mosquitto.log
i've this error: 1610030766: Client 'unknown' closed its connection. when i connect with REACTICZ.

@t0mg
Copy link
Collaborator

t0mg commented Jan 7, 2021

Hey, yeah that seems linked to the MQTT update indeed.

Unfortunately I'm no longer able to maintain or debug reacticz*, so I can't help you with this issue.

Here are a few things you could try:

  • try without auth to narrow down the issue
  • look for clues in mosquitto changelog (breaking changes / deprecations)
  • update reacticz deps in package.json (especially MQTT.js) and rebuild reacticz
  • look for similar issues in other projects that use MQTT.js

(* if anyone is interested in taking over it would be nice !)

@t0mg
Copy link
Collaborator

t0mg commented Jan 7, 2021

PS: Reacticz should be rewritten anyway if the MQTT loopback is removed, see domoticz/domoticz#4035

@wewa00
Copy link
Contributor Author

wewa00 commented Jan 9, 2021

The issue following. The browser blocks connection to the MQTT server, because I access domoticz via https. But the browser detects the mqtt connection as unsecure (non https) and blocks it therefore.

@secator76
Copy link

The issue following. The browser blocks connection to the MQTT server, because I access domoticz via https. But the browser detects the mqtt connection as unsecure (non https) and blocks it therefore.

same for me

@wewa00
Copy link
Contributor Author

wewa00 commented Jan 10, 2021

And another additional information: It is only possible to connect to MQTT Websocket port, if TLS is disabled there.

UPDATE: In case you want to connect to a TLS secured MQTT Websocket port, you need to use wss:// instead of ws:// for the MQTT Broker URL (see https://stackoverflow.com/a/46559376/1528248).

@wewa00
Copy link
Contributor Author

wewa00 commented Jan 10, 2021

@t0mg regarding support and contribution, is there any channel where we could exchange (like discord)?

@t0mg
Copy link
Collaborator

t0mg commented Jan 11, 2021

Nope no Discord sorry, but Github issues should be enough :)

@wewa00
Copy link
Contributor Author

wewa00 commented Jan 11, 2021

OK, you saw my pull request (#40) already. I think we should continue using MQTT because that is working good and it does not need lots of changes. So what stays open in my eyes because of domoticz/domoticz#4035 is following.

But I could need some introduction here in how this program is structured because I am not used to JavaScript developing nore to node.js.

PS: Another issue which should be addressed is, that the MQTT und Domoticz credentials are stored in clear text in the Browsers Local Storage. I think those should be encrypted by some protected key for security reasons.

@t0mg
Copy link
Collaborator

t0mg commented Jan 12, 2021

Not sure why a polling timer would be necessary if Domoticz properly publishes state changes? It kind of defeats the purpose of using MQTT/websockets too.

It's a react app, which typically means that the data flow is unidirectional. A Reacticz dashboard is a list of user selected devices (with their position in the grid). Reacticz calls Domoticz to fetch these devices, tries to figure out their type and calls the proper widget for each. In the widgets, we define how to render the device state and what the available user actions are. When a user presses a button, we either send an MQTT message or a JSON command. The app monitors incoming messages at a global level, and updates the state of all widgets, which in turn re-render to reflect the changes. In other words, tapping a button in a widget does not update the UI directly, it only sends the message to Domoticz. The UI is updated by state changes at the app level that cascade down to each relevant widget. This way we are guaranteed to be consistent with the state of Domoticz, and thanks to MQTT over websockets, it's faster than polling solutions. We do use polling for some cases that are not supported by the MQTT implementation (eg IIRC, scenes dont trigger MQTT updates for all devices).

Reacticz was bootstrapped with Create React App which has good documentation for getting started.

Regarding credentials, you are correct: they are stored in clear text and that's not ideal. We could put these in a cookie instead with an expiry date but I'm guessing most users would not be pleased with the change, and it would still be clear text. I don't see how these credentials could be locally and securely encrypted in a reversible way (we need them in clear text to connect to Domoticz and the MQTT broker). Instead there should likely be a token-based auth with a cookie, but I don't know if token-based solutions are available for both MQTT and Domoticz, maybe that's worth exploring if you feel strongly about it ?

@wewa00
Copy link
Contributor Author

wewa00 commented Jan 12, 2021

The issue here with Domoticz is, that Domoticz is not really notifying over every value change (e.g. for temperature sensor, ...). I noticed this in a private project already where I use Domoticz as an UI for a heationg control based on python and MQTT.

I solved it there by polling the relevant values. And I think it would be good to do the same for Reacticz.

In fact it is not really a polling, you simply trigger Domoticz to broadcast the value and react then, because you subscribed the Domoticz/out topic.

So is there already some timer callback where this "value update trigger functionality" could be implemented?

@wewa00 wewa00 mentioned this issue Jan 23, 2021
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