Page 1 of 1

node.js and mqtt to parse log file

Posted: Sun Feb 16, 2014 11:06 pm
by Kroonen
Hi,

After the blog domoticaforum.eu/viewtopic.php?f=23&amp ... amp;t=9446 post of Pieter, I like how node.js and mqtt works, the realtime data.

I'm using fhem for my software, and all the hardware logs everything in files. So for my outdoor oregon sensor gives this output

tail -f /var/log/fhem/buiten-2014.log

2014-02-16_21:54:45 Buitentemp temperature: 5.8
2014-02-16_21:54:45 Buitentemp humidity: 31
2014-02-16_21:54:45 Buitentemp battery: ok
2014-02-16_21:54:45 Buitentemp T: 5.8 H: 31 BAT: ok
2014-02-16_21:55:26 Buitentemp temperature: 5.8
2014-02-16_21:55:26 Buitentemp humidity: 31
2014-02-16_21:55:26 Buitentemp battery: ok
2014-02-16_21:55:26 Buitentemp T: 5.8 H: 31 BAT: ok

Now I thought that it should be possible to create a node.js file that check this log and publish the change values to the mqtt broker and than create a server.js and and an html file to publish it.

I don't know how to start, because te smart meter example of Pieter reads serial and here i want to read output of a file.

Any help would be fine

regards Richard

Re: node.js and mqtt to parse log file

Posted: Mon Feb 17, 2014 12:19 am
by Digit
I've never done something like that, but this is what I found by using a search engine searching for "node.js read log file":

http://stackoverflow.com/questions/8993 ... in-node-js

Maybe this will help you.

Re: node.js and mqtt to parse log file

Posted: Mon Feb 17, 2014 10:33 am
by Bwired
is this coming from the Rfxcom
there is a nodejs for this, better is perhaps to change the interface......
https://github.com/bigkevmcd/node-rfxcom

Re: node.js and mqtt to parse log file

Posted: Mon Feb 17, 2014 9:33 pm
by Kroonen
Hi,

I found that there is a mosquito_pub command line executable. In can use notify in them to execute a command.
I use this to send the temperature to the message broker
define Notify_Buitentemp notify Buitentemp "/usr/bin/mosquitto_pub -h 192.168.180.2 -t smartmeter/test -m "$EVTPART1""
I'm using still de server.js and smart meter.html, and the mqtt message appears
Laatste bericht: smartmeter/test, 7.9 at: 20:24:20 CET
But the problem is, How to I get this message in the website, is this in smart meter.html or server.js. I can't find for example the consumed_high in the files
Laatste bericht: smartmeter/consumed_high, 130.85 at: 20:30:17 CET
How should i get the test in webpage?

regards Richard

Re: node.js and mqtt to parse log file

Posted: Mon Feb 17, 2014 11:21 pm
by Kroonen
found in the smartmeter.html with the div id

regards Richard

Re: node.js and mqtt to parse log file

Posted: Tue Feb 18, 2014 10:29 pm
by Bwired
right :)

this is the line in smartmeter.html

tp is the topic and the ID gets the value from the topic
$('#'.concat(tp)).html(msg.payload);