raspi-sensors
Version:
Raspberry-pi plugin to easily fetch data from GPIO and i2c sensors
45 lines (34 loc) • 933 B
JavaScript
// Load raspi-sensors plugin
var RaspiSensors = require('../build/raspi-sensors');
console.log('raspi-sensors test v0.1');
// Create some sensors
var TSL2561 = new RaspiSensors.Sensor({
type : "TSL2561",
address : 0X39
}, "light_sensor");
var BMP180 = new RaspiSensors.Sensor({
type : "BMP180",
address : 0x77
}, "temp_sensor");
// Define a callback
var dataLog = function(err, data) {
if(err) {
console.error("An error occured!");
console.error(err.cause);
return;
}
// Only log for now
console.log(data);
}
// Try to fetch right now a value
BMP180.fetch(dataLog);
// Fetch some value at a certain interval
TSL2561.fetchInterval(dataLog, 4);
BMP180.fetchInterval(dataLog, 5);
// After 20s of logging, stop everything
setTimeout(function() {
console.log("Time to stop the logging of values!");
TSL2561.fetchClear();
BMP180.fetchClear();
}, 20000)
console.log('Control send back to the main thread');