Skip to content

Instantly share code, notes, and snippets.

@don
Last active September 24, 2015 05:28
Show Gist options
  • Save don/0c6cee0fdec1484dab33 to your computer and use it in GitHub Desktop.
Save don/0c6cee0fdec1484dab33 to your computer and use it in GitHub Desktop.
Code snippets for Bluetooth Low Energy Raspberry Pi presentation at Maker Faire NY 2015
var TemperatureCharacteristic = function() {
TemperatureCharacteristic.super_.call(this, {
uuid: 'bbb1',
properties: ['read', 'notify'],
});
};
util.inherits(TemperatureCharacteristic, Characteristic);
TemperatureCharacteristic.prototype.onSubscribe
= function(maxValueSize, updateValueCallback) {
this.changeInterval = setInterval(function() {
sensor.temperature(sensorId, function(err, result) {
if (result != lastTemp) {
lastTemp = result;
var data = new Buffer(4);
data.writeFloatLE(result, 0);
updateValueCallback(data);
}
});
}.bind(this), 2000);
}
TemperatureCharacteristic.prototype.onUnsubscribe = function() {
console.log('TemperatureCharacteristic unsubscribe');
if (this.changeInterval) {
clearInterval(this.changeInterval);
this.changeInterval = null;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment