Created
July 28, 2015 16:15
-
-
Save sander/a4dc79c7795700856cf2 to your computer and use it in GitHub Desktop.
Polar H7 in Node
This file contains hidden or 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 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