jimmyeao / TEAMS2HA

24 stars 1 forks source link

MQTT over websockets #32

Closed mekaneck closed 7 months ago

mekaneck commented 7 months ago

Is your feature request related to a problem? Please describe. I'd like to use this program on a computer that is often on VPN, and therefore I need to connect to my MQTT server which would be on an external network. In order to set up my MQTT server to handle requests from the outside world I need to configure my reverse proxy for that purpose. However setting up a reverse proxy is easy for HTTP(s) and not so easy for other protocols.

Describe the solution you'd like I'd like MQTT over websockets to be an option that can be selected

Describe alternatives you've considered I've tried configuring NGINX proxy manager to use a stream and just forward the TCP packets, but that doesn't allow using a subdomain and also requires handling the TLS via some other means and requires exposing another port to the internet.

jimmyeao commented 7 months ago

Thanks, I'll take a look at implimenting this!

jimmyeao commented 7 months ago

OK, progress i have this now: image and NGINX Proxy Manager set to accept https and forward to 9001 Mosquitto is configured with letsencrypt and mine accepts normal mqtt, tls secured mqtt and wss:

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

allow_anonymous false
password_file /etc/mosquitto/passwd

listener 1883

listener 8883
cafile /etc/mosquitto/certs/fullchain.pem
certfile /etc/mosquitto/certs/cert.pem
keyfile /etc/mosquitto/certs/privkey.pem

listener 9001
protocol websockets
cafile /etc/mosquitto/certs/fullchain.pem
certfile /etc/mosquitto/certs/cert.pem
keyfile /etc/mosquitto/certs/privkey.pem

and all appears to be working. I have some tests to walk through to make sure everything is good and nothing is broken, then I'll release it, or in the meantime, you can pull the dev branch and try it yourself if you have VIsual Studio 2022

jimmyeao commented 7 months ago

Update pushed, let me know how you get on

mekaneck commented 7 months ago

This works perfectly, this is fantastic! Thank you!!

mekaneck commented 7 months ago

One minor bug I noticed, and I can't tell if this is related to MQTT with Websockets or not (since I can only test with Websockets enabled), but the MQTT connection status shows correctly in the window when open, but shows incorrectly when viewing the right-click menu when minimized.

Both images below were taken when MQTT server was connected and communicating normally:

From open window:

From right-click menu from system tray while app is minimized. Note that MQTT says "disconnected" even though it is not.

jimmyeao commented 7 months ago

Thanks, ill look into this!

jimmyeao commented 7 months ago

Fix implemented, will be in the next release

jimmyeao commented 7 months ago

closed in new release