public
Last active

temperature from raspberry pi

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/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]);
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.