Skip to content

Instantly share code, notes, and snippets.

@TheArmagan
Created May 26, 2024 14:39
Show Gist options
  • Save TheArmagan/3ae8e8b8ccd9599828c18ef61440f18e to your computer and use it in GitHub Desktop.
Save TheArmagan/3ae8e8b8ccd9599828c18ef61440f18e to your computer and use it in GitHub Desktop.
ELK-BLEDOM led controller using nodejs noble
const noble = require('@abandonware/noble');
noble.on('stateChange', (state) => {
if (state === 'poweredOn') {
noble.startScanningAsync([], false);
}
});
function buildColorBuffer(r, g, b) {
return Buffer.from([0x7e, 0x00, 0x05, 0x03, r, g, b, 0x00, 0xef]);
}
noble.on('discover', async (peripheral) => {
if (peripheral.advertisement.localName.includes("ELK-BLEDOM")) {
noble.stopScanning();
await peripheral.connectAsync();
console.log('connected to peripheral: ' + peripheral.uuid);
const { characteristics } = await peripheral.discoverAllServicesAndCharacteristicsAsync();
const writer = characteristics.find((c) => c.properties.includes("writeWithoutResponse"));
writer.writeAsync(buildColorBuffer(0, 0, 255), true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment