Created
May 26, 2024 14:39
-
-
Save TheArmagan/3ae8e8b8ccd9599828c18ef61440f18e to your computer and use it in GitHub Desktop.
ELK-BLEDOM led controller using nodejs noble
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('@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