Multiple FLM discovery

In the discussion on nicely designed gauges the request was raised to go beyond single-FLM installations.
If you have more than one FLM installed, you instantly get yourself the question on how to control them together.
Current scripts deal with a single instance only; but as we know Bart, there is already a solution: each FLM advertises its service(s) via Bonjour.
Thus the idea to enhance the single-instance persistence and visualization services with an appropriate FLM discovery; that is: integrate Bonjour into the persistence and visualization services to deal with "any number" of publishing sensor nodes...

This will be the story of this thread, so stay tuned for experiences gained and implementations provided...

gebhardm's picture

The solution is already just a tiny step away... Using the multicast DNS service discovery module for node.js (install npm mdns) the discovery is as easy as

  1. // import the mdns module
  2. var mdns = require('mdns');
  3. // watch all mqtt servers
  4. var browser = mdns.createBrowser(mdns.tcp('mqtt'));
  5. browser.on('serviceUp', function(service) {
  6.            console.log("service up: ", service);
  7.            });
  8. browser.on('serviceDown', function(service) {
  9.            console.log("service down: ", service);
  10.            });
  11. browser.start();

provides in my case for the Fluksometer following object
  1. service up:  { interfaceIndex: 4,
  2.   type:
  3.    { name: 'mqtt',
  4.      protocol: 'tcp',
  5.      subtypes: [],
  6.      fullyQualified: true },
  7.   replyDomain: 'local.',
  8.   flags: 2,
  9.   name: 'MQTT Broker on flukso-xxxxxx',
  10.   networkInterface: 'en0',
  11.   fullname: 'MQTT\\032Broker\\032on\\032flukso-xxxxxx._mqtt._tcp.local.',
  12.   host: 'flukso-xxxxxx.local.',
  13.   port: 1883,
  14.   addresses: [ '192.168.0.50' ] }

So the address(es) can easily be obtained and listened at.
Integration into the panel and chart will follow.
...to be continued...

gebhardm's picture

The expert sees it instantly, it should have been npm install mdns, of course. Put the first code block with a text editor into a file, for example mdns_test.js, and run it with node node mdns_test.js - et voila, surprise :-)

icarus75's picture

I knew you'd scratch this itch sooner rather than later. I once made a Firefox demo using the DNSSD plugin to have FLM LAN auto-discovery in the browser. Got the demo working, but since not all OS'es have a bonjour daemon running, and even less browsers support mDNS (as evidenced on the former URL) it was only good for a demo. For M-to-M it's merely an npm install away.

Happy coding!
/Bart

Pietro Spina's picture

nice... :-)

I was just about to post a step by step "copy paste how-to" in its own thread. It's based on the single flm code at https://github.com/gebhardm/flmdisplay

Should I hold off for a day or 2 (if this integration is close) or post ASAP with the hope that more eyes = more input.

cheers,
P

gebhardm's picture

The panel - as a first shot - has now automatic service discovery capabilities (currently tested with one FLM only; will test with a second on the weekend); see https://github.com/gebhardm/flmdisplay/tree/master/panel for the update - and perform a git pull in your cloned flmdisplay folder to get the updated version. Easier as I thought (still not really used to non-blocking programming); 'persist' to follow, 'chart' remains unchanged...

gebhardm's picture

As I forgot - you have to install another node module: npm install mdns as described in the README

Pietro Spina's picture

It's working with 3 Fluksometer on the network & finds all 9 gauge and displays.
:-D
I had to sudo apt-get install build-essential as well as maybe some other things that might not have been necessary. (I got lazy and used a fire hose when a watering can might have been fine.)

also, I chose to do...
git fetch --all
git reset --hard origin/master
In the panel directory as the pull would not overwrite the files without committing my changes. Careful though, the above will nuke the dir and replace everything.

gebhardm's picture

If you did changes you may have done a git stash before the git pull to send them into the "git nirvana", but still get a change to "somehow" retrieve them again...

Pietro Spina's picture

Noticed you made the updates to persist. Tested and working on fresh install. I updated my How-To to reflect the changes to the scripts and the new requirements due to MDNS. (Also, less logging in and out of mysql) thanks for the tip.

Pietro Spina's picture

Also, though the discovery works, I get the following warnings. If you are building and running on a mac you might not be getting them.

  1. *** WARNING *** The program 'nodejs' uses the Apple Bonjour compatibility layer of Avahi.
  2. *** WARNING *** Please fix your application to use the native API of Avahi!
  3. *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs>
  4. *** WARNING *** The program 'nodejs' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
  5. *** WARNING *** Please fix your application to use the native API of Avahi!
  6. *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=nodejs&f=DNSServiceRegister>

I suspect that if you made the changes they suggest you would then get warnings on your mac... or maybe the isue is something deeper in mdns and not even worth bringing up... if so, please disregard. :-)

gebhardm's picture

Note: The warnings are coming from the mdns modules, not my code; I experienced the same when using the scripts on a RasPi and also have issues in correctly determining the ip address (the many unresolved issues in the mdns github show what I experience with a lot of open source stuff: maintenance is not guaranteed - THIS ALSO AS A WORD OF WARNING TO CERTAIN PEOPLE EXPECTING OFF-THE-SHELF SOFTWARE WITH WARRENTY FOR NOTHING). I started to look for an alternative to using 'mdns', but didn't find such so far. So any hint is welcome.
If you experience issues, change back to the manually assigned IP address version (git checkout a5f0b21042); I'll see to set a tag on this version for easier retrieval...

gebhardm's picture

FYI - I split the manual and automated IP-address-determination versions of the scripts into different branches: 'master' will be the main path of evolution, thus hold the "automated" variant; 'manual-ip' will be the path of the manually set, single IP-address version of the scripts.
So, if you git clone http://github.com/gebhardm/flmdisplay by default you are in 'master'; with git checkout manual-ip you may switch to the original version with the little need to manually adapt the scripts to your FLM's local IP address.