node.js and mqtt to parse log file

Forum about MQTT, machine-to-machine (M2M), "Internet of Things" and Node.js

Moderators: Digit, Rene, Willem4ever, Bwired

Post Reply
Kroonen
Member
Member
Posts: 302
Joined: Mon Oct 01, 2007 6:38 pm
Location: Netherlands

node.js and mqtt to parse log file

Post 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
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: node.js and mqtt to parse log file

Post 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.
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Re: node.js and mqtt to parse log file

Post 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
Kroonen
Member
Member
Posts: 302
Joined: Mon Oct 01, 2007 6:38 pm
Location: Netherlands

Re: node.js and mqtt to parse log file

Post 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
Kroonen
Member
Member
Posts: 302
Joined: Mon Oct 01, 2007 6:38 pm
Location: Netherlands

Re: node.js and mqtt to parse log file

Post by Kroonen »

found in the smartmeter.html with the div id

regards Richard
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Re: node.js and mqtt to parse log file

Post 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);
http://www.bwired.nl Online Home, Domotica, Home Automation. Weblog. http://blog.bwired.nl
Post Reply

Return to “MQTT & Node.js”