Help request for Gebhard Combined script

Hi Gebhard,

I've been playing with your excellent mqtt scripts trying to get the combined to work from https://github.com/gebhardm/flmdisplay , but with no luck.

I have the following displayed when starting the node:

  1. www:combined vk2him$ node serve_flmdata.js
  2. Database flm successfully connected
  3. Detected MQTT service on: 192.168.1.73:1883
  4. Create/connect to config table successful...
  5. Create/connect to data table successful...

However when I navigate to localhost:1080 I get the following displayed

  1. Latest MQTT message: no message received

The mysql table is also empty.

I can connect fine with mosquito with no problem as you can see:

  1. www:combined vk2him$ mosquitto_sub -h 192.168.1.73 -p 1883 -v -t /sensor/#
  2. /sensor/c7c90d029e018769b5fb26380c369845/counter [1428230773,924264,"Wh"]
  3. /sensor/c7c90d029e018769b5fb26380c369845/gauge [1428230775,590,"W"]
  4. /sensor/c7c90d029e018769b5fb26380c369845/gauge [1428230776,586,"W"]
  5. /sensor/c7c90d029e018769b5fb26380c369845/gauge [1428230777,596,"W"]
  6. /sensor/c7c90d029e018769b5fb26380c369845/gauge [1428230778,588,"W"]
  7. /sensor/c7c90d029e018769b5fb26380c369845/counter [1428230779,924265,"Wh"]

As well as the latest versions, I have even tried installing an older 0.9 version of socket.io but it fails too:

  1. npm install socket.io@"~0.9.1"

I have tried your other older scripts by using the 0.9 version of socket.io but I always get this:

  1. Latest MQTT message: no message received

So I was wondering if I have done something wrong, or if my FLM needs something else to make it work? I am running Version 2.32

Thanks
Ian

gebhardm's picture

Respectively (in the "combined" script)

  1.     mqttclient.on("connect", function() {
  2.         console.log("Connected to " + service.addresses[0] + ":" + service.port);
  3.         // for the persistence subscription is needed:        
  4.         mqttclient.subscribe("/device/+/config/sensor");
  5.         mqttclient.subscribe("/sensor/+/gauge");
  6.         mqttclient.subscribe("/sensor/+/counter");
  7.     });

Thus, console.log the content of "service" to see what address snipets are passed; better try with the "simple graph" from https://github.com/gebhardm/energyhacks/tree/master/Graph as you deal with static IP addresses here and thus can reduce by one source of errors...

vk2him's picture

I tried the simple graph from master and changed to use static ip:

  1. function mqttconnect() {
  2.     mqttclient = mqtt.connect(host: "192.168.1.73", port: 1883 );
  3.    
  4.     console.log("Detected MQTT service on: " + mqttbroker + ":" + mqttport);
  5.     // log connection
  6.     mqttclient.on("connect", function() {
  7.         console.log("Connected to " + mqttbroker + ":" + mqttport);
  8.     });

It only gives this:

  1. www:Graph vk2him$ node serve_mqtt.js
  2. Detected MQTT service on: 192.168.1.73:1883

So I assume it means I'm either connecting but not getting a 'connect" back, or it's just not connecting at all ...

vk2him's picture

Sorry - code should have been

  1. function mqttconnect() {
  2.  mqttclient = mqtt.connect({host: "192.168.1.73", port: 1883} );
  3.    
  4.     console.log("Detected MQTT service on: " + mqttbroker + ":" + mqttport);
  5.     // log connection
  6.     mqttclient.on("connect", function() {
  7.         console.log("Connected to " + mqttbroker + ":" + mqttport);
  8.     });

gebhardm's picture

It is not connecting at all... Check also your local firewall settings if port 1883 is open;
I just had a fresh install on a windows PC without an FLM, but mosquitto and node v0.12.2; I even got it running on plain "127.0.0.1", thus within the same machine, so there is something dubious in your environment...
The code is

  1. // specify here your MQTT broker's data
  2. var mqttbroker = "192.168.1.73", mqttport = "1883";
  3.  
  4. [...]
  5.  
  6. function mqttconnect() {
  7.     mqttclient = mqtt.connect({
  8.         host: mqttbroker,
  9.         port: mqttport
  10.     });
  11.     // log connection
  12.     mqttclient.on("connect", function() {
  13.         console.log("Connected to " + mqttbroker + ":" + mqttport);
  14.     });

Use the variable to alter the IP address; therefor I put them in there...
Irritatingly the .on("connect")-event gets never fired...

vk2him's picture

Yes, the code you have above is exactly what I had originally - I tried hand-coding the IP into the mqtt.connect function to see if it made a difference, which it didn't. Yes, something very strange in my environment as the .on("connect" event is never fired. I have also tried the same code on another Mac and a Windows machine with the same.

There is no firewall on the Mac, I can access port 1883 from the Mac using mosquito so it must be "node" or "mqtt.connect" functionality issues .. here is mosquito proving I can access FLM properly

  1. www:combined vk2him$ mosquitto_sub -h 192.168.1.73 -p 1883 -v -t /sensor/#
  2. /sensor/c7c90d029e018769b5fb26380c369845/counter [1428230773,924264,"Wh"]
  3. /sensor/c7c90d029e018769b5fb26380c369845/gauge [1428230775,590,"W"]
  4. /sensor/c7c90d029e018769b5fb26380c369845/gauge [1428230776,586,"W"]
  5. /sensor/c7c90d029e018769b5fb26380c369845/gauge [1428230777,596,"W"]
  6. /sensor/c7c90d029e018769b5fb26380c369845/gauge [1428230778,588,"W"]
  7. /sensor/c7c90d029e018769b5fb26380c369845/counter [1428230779,924265,"Wh"]

Thanks for your patience, I'll think some more ...

gebhardm's picture

Try it with a de-install and plain re-install of the simplest visualization...

  • Get the current node.js installer from nodejs.org and install it.
  • Download (better git clone) the energyhacks and decompress them
  • Change to the ./gauge or ./graph folder.
  • Run npm install to get the required modules; check the install log for things that may went wrong (usually all is well even though there were warnings)
  • Change the MQTT broker's IP address in serve_mqtt.js
  • Run node serve_mqtt.js - the MQTT should connect...
  • Point your web browser to http://localhost:1080
  • Now the gauge or graph should appear...

If not, well, you might try another hobby ;-) (I checked this now on four different computers, with Mac OS, Debian Linux and Windows)

gebhardm's picture

@VK2HIM - did you get the MQTT receiver working with node by now?

vk2him's picture

@GEBHARDM - No, I have had no luck and I'm hoping when the new firmware for Flukso is released it will have this pre-loaded :)

gebhardm's picture

As Bart is working on TMPO with Python and Pandas I doubt preloading :-/

vk2him's picture

Hi @GEBHARDM

After Bart remote updated my FML to 245 your script worked immediately - so somehow my FLM wasn't working properly with mqtt.

Many thanks - I like it a lot,
Ian

vk2him's picture

Hi Markus,

I scp copied the files from /www/ onto the FLM to use it locally using the instructions in https://github.com/gebhardm/flmlocal

All is working well except for the Chart page won't display the charts .. I get this displayed "Query request sent..." with no graphs.

Do I also need to scp the /usr/ files over to the FML as I see that queryd.lua isn't on the FML?
Regards
Ian

gebhardm's picture

As the query-daemon is "my invention", sure, this is currently not available on the FLM by nature; so yes, you have to copy this as well and start it corresponding to the description in the ReadMe.
Be aware that there a actually two changes: The query "daemon" (new) and an alteration to the flukso daemon to publish its configuration - to get the real sensor names. The flukso daemon version is 2.4.4, but should be "equal" to the 2.4.5 version - at own risk, as depicted by the MIT license.

A remark of warning: The flmlocal stuff referred to here is working on FLM version 2.4.4 and 2.4.5; with upcoming versions there is a change in the original firmware that may conflict with this implementation - so always "know what you are doing".

In any case, a factory reset of your FLM will clean up any mess you may have caused.

vk2him's picture

Perfect - yes it is now working very well - thank you for your efforts, it looks excellent!