Commit f3f70388 authored by Spencer Williams's avatar Spencer Williams
Browse files

read sensor data

parent 6eff209a
......@@ -32,6 +32,7 @@ class Device {
}
this.readFirmware()
.then(this.enableLuxometer.bind(this))
.then(() => {
resolve(this);
})
......@@ -42,6 +43,29 @@ class Device {
});
});
}
enableLuxometer() {
return new Promise((resolve) => {
console.log(`${this.id}: enableLuxometer`);
this.bleDevice.enableLuxometer(resolve);
});
}
notifyLuxometer() {
return new Promise((resolve) => {
console.log(`${this.id}: notifyLuxometer`);
this.bleDevice.notifyLuxometer(resolve);
});
}
onLuxometerChange(sendTelemetry) {
console.log(`${this.id}: set up onluxchange`);
this.bleDevice.on('luxometerChange', (lux) => {
sendTelemetry(this, lux);
});
return this.notifyLuxometer();
}
}
module.exports = Device;
......@@ -38,6 +38,10 @@ function onDiscover(beaconInst) {
// Connect to device and setup
device.setUp()
.then(() => {
device.onLuxometerChange((d, lux) => {
console.log(`Device ${d.id} lux: ${lux.toFixed(1)}`);
});
// Wait for as long as possible before scanning again to avoid race
// conditions
startScanning();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment