victronenergy / venus-html5-app

HTML5 App including Javascript library that communicates with Venus OS over MQTT websockets
MIT License
98 stars 32 forks source link

fix(mqtt): connect to Venus MQTT via nginx websocket #387

Open mman opened 1 week ago

mman commented 1 week ago

This PR adds support to connect to Venus FlashMQ via nginx mapped websocket instead of using the port 9001.

It is implemented in two parts:

1. HTML 5 app

In the past the HTML5 app used window.location.hostname and hardcoded port 9001 to derive MQTT broker URL from the location where the HTML5 app is loaded. So when it is accessed remotely by connecting to Venus via http://cerbogx/app it would use the cerbogx hostname, and port 9001 to open WebSocket connection directly to FlashMQ web socket port 9001 as configured on Venus in /etc/flashmq/flashmq.conf.

In this new implementation it derives both hostname and port from the window.location and uses special request path /websocket-mqtt to connect to FlashMQ via Venus nginx mapping.

2. MFD Modules part

The MFD modules MqttStore allowed in the past to specify only host and port where to connect to the broker.

In the new implementation it also allows to override request path defaulting to websocket-mqtt so that complete broker URL can be composed. This is addressed in a separate PR here: https://github.com/victronenergy/victron-mfd-modules/pull/4

mman commented 1 week ago

The check failing is expected as this code relies on https://github.com/victronenergy/victron-mfd-modules/pull/4 that needs to be tagged first.