Created
November 24, 2014 20:51
-
-
Save nherment/0fde746666490f411059 to your computer and use it in GitHub Desktop.
beaglebone temperature/humidity monitor with metrano
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exec = require('child_process').exec | |
var Metrano = require('metrano) | |
var metrano = new Metrano('http://ice:3000/') | |
///home/nherment/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 P8_11 | |
exec('/home/nherment/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 P8_11', function(err, stdout, stderr) { | |
if(err) { | |
console.log(err); | |
} | |
if(stderr) { | |
console.error(stderr) | |
} | |
if(stdout) { | |
console.log('>', JSON.stringify(stdout)); | |
var match = /^Temp=(\d*\.?\d*)\*C\s+Humidity=(\d*\.?\d*)\%$/m.exec(stdout) | |
try { | |
var temperature = parseFloat(match[1]); | |
var humidity = parseFloat(match[2]); | |
console.log('h:', humidity, 't:', temperature); | |
metrano.save('temperature', 'beaglebone', temperature, Date.now(), function(err) { | |
if(err) { | |
console.log(err) | |
} else { | |
console.log('.'); | |
} | |
}) | |
metrano.save('humidity', 'beaglebone', humidity, Date.now(), function(err) { | |
if(err) { | |
console.log(err) | |
} else { | |
console.log('.'); | |
} | |
}) | |
} catch(err) { | |
console.log(err); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment