Skip to content

Instantly share code, notes, and snippets.

@sander
Created July 28, 2015 16:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sander/a4dc79c7795700856cf2 to your computer and use it in GitHub Desktop.
Save sander/a4dc79c7795700856cf2 to your computer and use it in GitHub Desktop.
Polar H7 in Node
var noble = require('noble');
var uuid = 'FIXME';
var charuuid = '2a37';
var srvuuid = '180d';
var fmt = 1;
noble.on('discover', function(p) {
if (uuid != p.uuid) return;
console.log('ja');
p.connect(function(err) {
console.log('connected');
p.discoverServices([srvuuid], function(err, ss) {
if (ss.length != 1) return;
console.log('service found');
ss[0].discoverCharacteristics([charuuid], function(err, cs) {
if (cs.length != 1) return;
console.log('characteristic found');
cs[0].notify(true);
cs[0].on('read', function(val, isNotification) {
var rate = val.readUInt8(1);
var n = (val.length - 2) / 2;
var rr = [];
for (var i = 0; i < n; i++) {
rr.push((val.readUInt16LE(2 + 2 * i) / 1024.0) * 1000.0);
}
console.log(rate, rr);
});
});
});
});
});
noble.on('stateChange', function(state) {
if (state == 'poweredOn') {
noble.startScanning();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment