Skip to content

Instantly share code, notes, and snippets.

@roosnic1
Created March 20, 2018 09:54
Show Gist options
  • Save roosnic1/720397c8b5660900bfe342a097819d11 to your computer and use it in GitHub Desktop.
Save roosnic1/720397c8b5660900bfe342a097819d11 to your computer and use it in GitHub Desktop.
Write to bluetooth
const noble = require('noble');
noble.on('discover', (peripheral) => {
console.log('Found device', peripheral.advertisement.localName);
if(peripheral.id === '9e359b047dfa4f07a404476dfacdd68a') {
console.log('Connectiing to Biscuit');
peripheral.connect((err) => {
if(err) {
console.log('Could not connect', err);
}
peripheral.discoverAllServicesAndCharacteristics((error, services, characteristics) => {
if(err) {
console.log('Could not discover', err);
}
//console.log('Discovered services', services);
console.log('Discovered chara..', characteristics);
characteristics.map((characteristic) => {
if(characteristic.properties.includes('writeWithoutResponse')) {
const data = Buffer.from('Hello Lolo');
characteristic.write(data, false)
}
})
});
});
}
});
noble.startScanning();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment