Closed microspace closed 8 years ago
Just so I understand correctly, you want to completely exit the program after reading the barometer? What happens the read value?
Yes, I want to completely exit the program. Program should return pressure value. Is it possible?
Here's a complete example, including a test program to try it out:
(test.js)
var cp = require("child_process");
var barometer = cp.spawn("node", [ "read-once-barometer" ]);
barometer.stdout.on("data", function (data) {
console.log("stdout: " + data);
});
barometer.stderr.on("data", function (data) {
console.log("stderr: " + data);
});
barometer.on("exit", function (code) {
console.log("child process exited with code " + code);
});
(read-once-barometer.js)
var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
io: new Edison(),
// this ensures that no other information is output
repl: false,
debug: false,
});
board.on("ready", function() {
var barometer = new five.Barometer({
controller: "BMP180"
});
barometer.on("data", function() {
process.stdout.write(this.pressure);
process.exit();
});
});
Thank you so much!
I launched barometer example from here http://johnny-five.io/examples/grove-barometer-edison/ How to read pressure data only ONCE, that exit program?