Created
December 9, 2012 23:27
-
-
Save JerrySievert/4247487 to your computer and use it in GitHub Desktop.
temperature from raspberry pi
This file contains hidden or 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
#!/usr/bin/env node | |
var fs = require('fs'); | |
function getTemperature (device) { | |
fs.readFile('/sys/bus/w1/devices/' + device + '/w1_slave', 'utf8', function (err, data) { | |
var output = data.match(/t=(\d+)/); | |
var calc = output[1] / 1000; | |
var tempf = ((calc * 9) / 5) + 32; | |
console.log("Sensor ID: " + device + ", Temp: " + calc + " (" + tempf + " F)"); | |
}); | |
} | |
fs.readFile('/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves', 'utf8', function (err, data) { | |
var parts = data.split("\n"); | |
parts.pop(); | |
for (var i = 0; i < parts.length; i++) { | |
getTemperature(parts[i]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment