Skip to content

Instantly share code, notes, and snippets.

@evanxd
Last active August 29, 2015 14:23
Show Gist options
  • Save evanxd/e23c805724cda59b8469 to your computer and use it in GitHub Desktop.
Save evanxd/e23c805724cda59b8469 to your computer and use it in GitHub Desktop.
Design BlueYeast
var Util = Bluetooth.Util;
var profile = [
{ alias: 'char1', service: 'uuid-s1', characteristic: 'uuid-c1' },
{ alias: 'char2', service: 'uuid-s2', characteristic: 'uuid-c1' },
{ alias: 'de1', service: 'uuid-s1', characteristic: 'uuid-c2', descriptor: 'uuid-d1' },
{ alias: 'de2', service: 'uuid-s1', characteristic: 'uuid-c2', descriptor: 'uuid-d2' }
];
var devices = Bluetooth.GATT.connect([
{ name: 'BT_DEVICE1', address: 'a0:21:3e:3d:e1:33', profile: profile },
{ name: 'BT_DEVICE2', address: 'a0:21:3e:3d:e1:34', profile: profile }
]);
devices[0].on('connect', function(device) {
var char2 = device.char2;
console.log('char2: ' + char2);
device.char1 = Util.toByteArray('EE');
device.disconnect();
});
devices[1].on('data', function(evt) {
var uuids = evt.uuids; // { service: 'uuid-s1', characteristic: 'uuid-c2', descriptor: 'uuid-d1' }
console.log('service: ' + uuids.service);
console.log('characteristic: ' + uuids.characteristic);
console.log('descriptor: ' + uuids.descriptor);
console.log(Util.toHexString(evt.data));
});
devices.forEach(function(device) {
device.on('error', function(error) {
console.log(error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment