Skip to content

Instantly share code, notes, and snippets.

@SamDecrock
Last active July 26, 2022 20:05
Show Gist options
  • Save SamDecrock/334b45ca6043c9cc9877f05dca38d6cc to your computer and use it in GitHub Desktop.
Save SamDecrock/334b45ca6043c9cc9877f05dca38d6cc to your computer and use it in GitHub Desktop.
Connecting to an Amazon Echo Button
var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();
var address = '50-dc-e7-a3-0b-e8';
btSerial.findSerialPortChannel(address, function(channel) {
btSerial.connect(address, channel, function() {
console.log('> connected to ' + address);
btSerial.on('data', function(buffer) {
console.log('> receiving ('+buffer.length+' bytes):', buffer);
var isPressed = buffer[buffer.length-2] == 0xc0;
console.log(' >> button is ' + (isPressed?'pressed':'released'));
});
}, function () {
console.log('> cannot connect');
});
}, function() {
console.log('found nothing');
});
process.on('SIGINT', function() {
console.log("> closing bluetooth connection.");
btSerial.close();
process.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment