Skip to content

@JerrySievert /gist:4247487
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.