Skip to content

Instantly share code, notes, and snippets.

@JerrySievert
Created December 9, 2012 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JerrySievert/4247487 to your computer and use it in GitHub Desktop.
Save JerrySievert/4247487 to your computer and use it in GitHub Desktop.
temperature from raspberry pi
#!/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