Created
March 20, 2018 09:54
-
-
Save roosnic1/720397c8b5660900bfe342a097819d11 to your computer and use it in GitHub Desktop.
Write to bluetooth
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
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