FLM MQTT broker to support web sockets [solved]

Jan-Piet Mens, one of the "masters" to test MQTT capabilities, in July 2014 described on how to make the mosquitto MQTT broker, which is also used on the FLM, supporting web sockets. See http://jpmens.net/2014/07/03/the-mosquitto-mqtt-broker-gets-websockets-s... - this I'd like to get implemented on the FLM as well, as then a "direct local gauge display" (with any cheap Android tablet) would be just some js-files and an additional html page on the FLM away.

And here is the solution: Beginning with the (yet experimental) FLM firmware version 2.4.4 the Fluksometer will natively support MQTT over websockets; to utilize this for a direct/local display served from the FLM's own web server, you may use my "develop" version of an FLM-AngularJS/jQuery-integrated gauge, graph and panel display (follow the link to GitHub).
Read this thread to get an understanding what happened so far and how to gain this native solution to display gauges (and panels and graphs) directly from your FLM.

AttachmentSize
FLMlocalGauge.png181.8 KB
gebhardm's picture

  1. #Allow access to MQTT over Websockets on the wan itf
  2. config rule
  3. option src wan
  4. option proto tcp
  5. option dest_port 8083
  6. option target ACCEPT

Does it already work to access the FLM from mqttws31.js via ws://<flm ip>:8083??? I have to check that.
Lucky the one that has proper documentation (no, code is not proper documentation, at least not in freaky web development times)

gebhardm's picture

Not in 2.3.2 :-( When will this be made available? Or how may I patch that myself? (I guess I have to set up an external compile environment as Pieter Meulenhoff explains in https://www.flukso.net/content/mqtt-nicely-designed-gauges - Thu, 08/05/2014 - 10:38) or wait for a release of 2.4.4?!

icarus75's picture

MQTT over websockets will indeed be included in the 24x release. If you'd like to start experimenting with this setup, I can trigger a remote firmware upgrade for your FLM. Just make sure to keep it online during the upgrade window.

gebhardm's picture

Hey Bart, yes, please - FLM is always on anyway. Thanks. Will provide feedback as usual. Best regards, Markus

icarus75's picture

Your FLM has successfully upgraded. Take those websockets for a spin! The quickest way to get started is to point your browser to the HiveMQ websocket client and fill in the proper connection parameters. Port should be 8083, no user/password required.

jgysenbergs's picture

Me too, me too ... if possible, that is. Tx - Jos

gebhardm's picture

I've already a local gauge that works just fine :-) - mqttsw31.js + justgage.js - Thanks for updating!
Now it's just a matter of bringing gauge.html + flm.logic.js to the FLM et voila, the FLM is capable to show gauges on any locally connected tablet...
See https://github.com/gebhardm/flmdisplay/tree/master/gauge
To be continued...

icarus75's picture

@jgysenbergs r244 has been served for you as well.
@*: r244 is a beta release. If you encounter any issues, please report them in dedicated forum threads.

Enjoy!

jgysenbergs's picture

Great! It took a while to figure out scp in OSX. Needed an extra '//', like this

scp * root@://www/

Thanks again!

gebhardm's picture

I will update the panel and graph as well and provide it for local utilization - maybe I integrate it in Bart's landing page in the same sense as the config pages; then everything should be fine (db and chart waiting for tmpo); the extra bootstrap.min.css will also vanish again as the FLM natively uses the bootstrap.css.
BTW: I didn't need the extra slashes in the terminal of OS 10.10... However, this is what man-pages and the '--help'-parameter are for ;-)

icarus75's picture

@gebhardm The FLM will now publish it's entire sensor configuration on MQTT topic '/sensor/config' in JSON format. You could filter out the active sensors ("enable":1) and render their gauges. A nice addition would be to display the counter value, if present, just below the gauge.

And yes, integration of the gauges as an extra tab on the local configuration page would be great.

gebhardm's picture

The counters are in the panel (not the gauge) already ;-) (to be provided) - and thanks for notifying on the /sensor/config - will use it, do they provide the "real names" also? Would instantly solve a request by Ryton. I will set up a proposal that you may evaluate and perhaps (royalty free ;-)) integrate...

icarus75's picture

The JSON object is a curated version of /etc/config/flukso, so all sensor configuration parameters are included. "Real names" will be found under the "function" entry. A "name" key would be a more obvious choice. "Function" is however an artefact from the past.

Should the local dash be merged into the mainline build under a OSI license, you will be handsomely rewarded in beers next time we meet in person.

gebhardm's picture

Update Gauge, panel, and graph and a very simple integration in the landing page (just the link in the navigation bar) are available. See the gauge section and copy the FLMlocal folder's content...
Currently the /sensor/config topic does not deliver any values, so the names are still IDs... (am I doing something wrong? QoS?)

gebhardm's picture

Remark to running the local visualization:
Jos was right, you need the dash at scp (I corrected the ReadMe and beg your pardon :-))
I experience connection losses on mqttws31; corresponding to the console there is a property passed that is unknown; this seems to be an issue within the mqttws31.js implementation - so just refresh your browser window in case the graph/panel/gauge stops; no cure at the moment.

gebhardm's picture

For easier consumption without overhead I created an own repository that will be the (new) home of all FLM local deployment hacks: https://github.com/gebhardm/flmlocal

cdr's picture

Hi, I'd like to beta test the new websocket release, can you remote upgrade?

Thanks

gebhardm's picture

FYI (Bart ;-)) - I experiment with an integrated version that fits natively into the FLM's AngularJS environment; under https://github.com/gebhardm/flmlocal/tree/develop the first, not yet nice, but working version of the "simple gauges" exists (note: the justgage gauges do not require jquery, like panel and graph do)

gebhardm's picture

Christmas update
I did "some" code cleanup and adaptation to the FLM-local gauge/graph/panel implementation using jquery - this is now also capable to support real sensor names, if the required patch of the flukso daemon code has been applied to make the FLM publish its configuration. As this is a little more complicated than just copying some files via scp, I leave this to the advanced users... (see https://github.com/gebhardm/flmlocal/blob/develop/usr/sbin/fluksod.lua respectively the hints in the develop branch of my repository)
The updated jquery version can be obtained from the master branch of https://github.com/gebhardm/flmlocal
Have fun - and still "Merry Christmas" ("Happy Chanukah" for the latecomers)

jgysenbergs's picture

Thanks again, Markus and Best Seasonal Wishes to you too!

gebhardm's picture

Now also available, the fully AngularJS/Flukso landing page integrated version of the gauge/panel/graph that does not leave the Flukso navigation tab - see https://github.com/gebhardm/flmlocal/tree/develop and don't be fooled by the "develop" branch - everything is always under development ;-) (find here also the flukso-daemon hack to enable configuration publication via MQTT)

Fluc's picture

Nice to see this is working in your browser without hassle.
Thanks Gebhardm for the code, thanks Bart for the beta firmware r244.
If possible, can you push this firmware to my Flm too, please ?
Just between 0h30 and 4h30 the Flm is not online (Belgium).
I hope everything is continued working fine like past 13 months.

Thanks and a Happy New Year.

Greenhouse's picture

Can I please have the r244? FLM is online all the time.

gebhardm's picture

end-of-thread
Web sockets are accessible; MQTT messages can be pushed through them; with the mosquitto rebuild it is stable (as of v245) and even persisted data can be retrieved via MQTT/TMPO-integration. All is available as an FLM integrated option, so everything is just fine :-)
For a quick-link to an implementation see the FLM local visualization capabilities.

icarus75's picture

@Greenhouse Your FLM is scheduled for a r245 upgrade within the hour.

Putting a lock on this thread.