Skip to content

Instantly share code, notes, and snippets.

@kolontsov
Created October 22, 2017 00:39
Show Gist options
  • Save kolontsov/352f51859d15ee4e66368122bbf4d7c5 to your computer and use it in GitHub Desktop.
Save kolontsov/352f51859d15ee4e66368122bbf4d7c5 to your computer and use it in GitHub Desktop.
Nespresso coffee machine BLE experiments (get AUTH_KEY with Android BT HCI log and Wireshark)
const noble = require('noble');
const SERVICE_UUID = '06aa1910f22a11e39daa0002a5d5c51b';
const TEMPERATURE = {low: '01', medium: '00', high: '02'};
const VOLUME = {ristretto: '00', espresso: '01', lungo: '02', americano: '04', hotwater: '05', recipe: '07'};
let brew_cmd = (vol, t)=>`0305070400000000${TEMPERATURE[t]}${VOLUME[vol]}`;
let process_char = char=>{
if (char.uuid=='06aa3a41f22a11e39daa0002a5d5c51b')
{
char.write(Buffer.from(AUTH_KEY, 'hex'));
console.log('Auth done');
}
else if (char.uuid=='06aa3a42f22a11e39daa0002a5d5c51b')
{
char.write(Buffer.from(brew_cmd('lungo', 'high'), 'hex'));
console.log('Brew done');
}
};
console.log('Waiting for device');
let discovered = 0;
noble.on('discover', machine=>{
if (discovered++)
return;
console.log(`Coffee machine found: ${machine.advertisement.localName} (${machine.address}), id=${machine.id}`);
noble.stopScanning();
machine.connect(err=>{
console.log('Connected')
// service/char discovery not needed, just write to appropriate characteristics
machine.discoverServices([], (err, services)=>
services.forEach(srv=>srv.discoverCharacteristics([], (err, chars)=>chars.forEach(char=>process_char(char)))))
});
});
noble.on('stateChange', state=>{
if (state=='poweredOn')
return void noble.startScanning([SERVICE_UUID], true);
noble.stopScanning();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment