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

node.js and mqtt to parse log file

Postby Kroonen » Sun Feb 16, 2014 10:06 pm

Hi,

After the blog domoticaforum.eu/viewtopic.php?f=23& ... 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
Kroonen
Member
Member
 
Posts: 302
Joined: October 2007
Location: Netherlands

Re: node.js and mqtt to parse log file

Postby Digit » Sun Feb 16, 2014 11:19 pm

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.
User avatar
Digit
Global Moderator
Global Moderator
 
Posts: 3388
Joined: March 2006
Location: Netherlands

Re: node.js and mqtt to parse log file

Postby Bwired » Mon Feb 17, 2014 9:33 am

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
User avatar
Bwired
Administrator
Administrator
 
Posts: 5305
Joined: March 2006
Location: Netherlands

Re: node.js and mqtt to parse log file

Postby Kroonen » Mon Feb 17, 2014 8:33 pm

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: October 2007
Location: Netherlands

Re: node.js and mqtt to parse log file

Postby Kroonen » Mon Feb 17, 2014 10:21 pm

found in the smartmeter.html with the div id

regards Richard
Kroonen
Member
Member
 
Posts: 302
Joined: October 2007
Location: Netherlands

Re: node.js and mqtt to parse log file

Postby Bwired » Tue Feb 18, 2014 9:29 pm

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
User avatar
Bwired
Administrator
Administrator
 
Posts: 5305
Joined: March 2006
Location: Netherlands


Return to MQTT & Node.js

Who is online

Users browsing this forum: No registered users and 1 guest