Last active
September 24, 2015 05:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TemperatureCharacteristic = function() { | |
TemperatureCharacteristic.super_.call(this, { | |
uuid: 'bbb1', | |
properties: ['read', 'notify'], | |
}); | |
}; | |
util.inherits(TemperatureCharacteristic, Characteristic); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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