From f3903379072770ac41077b0f6ad3b060767e9a03 Mon Sep 17 00:00:00 2001 From: Marek Serafin Date: Sun, 22 Dec 2024 13:59:53 +0100 Subject: [PATCH] fix(hci): bumping `node-bluetooth-hci-socket` to address packet parser issue --- README.md | 22 +++++++++++++++------- index.d.ts | 4 ++++ package-lock.json | 8 ++++---- package.json | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6d0f43a7..fbd13c64 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,12 @@ This fork of `noble` was created to introduce several key improvements and new f 2. **macOS Native Bindings Fix**: I have fixed the native bindings for macOS, ensuring better compatibility and performance on Apple devices. -3. **New Features**: - - A `setAddress` function has been added, allowing users to set the MAC address of the central device. +3. **Windows Native Bindings Fix**: I have fixed the native bindings for Windows, adding support for `Service Data` from advertisements. + +4. **New Features**: + - A `setAddress(...)` function has been added, allowing users to set the MAC address of the central device. - A `connect(...)/connectAsync(...)` function has been added, allowing users to connect directly to specific device by address/identifier without a need to prior scan. + - A `waitForPoweredOn(...)` function to wait for the adapter to be powered on in await/async functions. - Additionally, I plan to add raw L2CAP channel support, enhancing low-level Bluetooth communication capabilities. If you appreciate these enhancements and the continued development of this project, please consider supporting my work. @@ -49,14 +52,16 @@ const noble = require('@stoprocent/noble'); ```javascript // Read the battery level of the first found peripheral exposing the Battery Level characteristic +const noble = require('../'); -const noble = require('@stoprocent/noble'); - -noble.on('stateChange', async (state) => { - if (state === 'poweredOn') { +async function run() { + try { + await noble.waitForPoweredOn(); await noble.startScanningAsync(['180f'], false); + } catch (error) { + console.error(error); } -}); +} noble.on('discover', async (peripheral) => { await noble.stopScanningAsync(); @@ -69,6 +74,9 @@ noble.on('discover', async (peripheral) => { await peripheral.disconnectAsync(); process.exit(0); }); + +run(); + ``` ## Use Noble With BLE5 Extended Features With HCI diff --git a/index.d.ts b/index.d.ts index 9b6942b9..0ec9f800 100644 --- a/index.d.ts +++ b/index.d.ts @@ -54,6 +54,10 @@ export declare function removeListener(event: string, listener: Function): event export declare function removeAllListeners(event?: string): events.EventEmitter; +export var state: "unknown" | "resetting" | "unsupported" | "unauthorized" | "poweredOff" | "poweredOn"; +/** + * @deprecated Use `state` instead. + */ export var _state: "unknown" | "resetting" | "unsupported" | "unauthorized" | "poweredOff" | "poweredOn"; export var _bindings: any; diff --git a/package-lock.json b/package-lock.json index e07a4e36..bb4f320d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,7 +44,7 @@ "node": ">=14" }, "optionalDependencies": { - "@stoprocent/bluetooth-hci-socket": "^1.4.2" + "@stoprocent/bluetooth-hci-socket": "^1.4.3" } }, "node_modules/@ampproject/remapping": { @@ -2086,9 +2086,9 @@ "license": "(Unlicense OR Apache-2.0)" }, "node_modules/@stoprocent/bluetooth-hci-socket": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/@stoprocent/bluetooth-hci-socket/-/bluetooth-hci-socket-1.4.2.tgz", - "integrity": "sha512-VlULC6DCrZ3XjOMk9dwQdem42uhZEZegf/Okegyip00TV2gKGpo6F5dU+f+CsJGiSGj1lYQOBvC+f6voq5d1nQ==", + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@stoprocent/bluetooth-hci-socket/-/bluetooth-hci-socket-1.4.3.tgz", + "integrity": "sha512-cBHrMyRdfjWxQkS4fnEm1PdMiVknQfdCB37BP2DH0sHkLvs/BnOrNswqs5wdoZ5rgHvbqlZFZv/o/RYElL9XRg==", "hasInstallScript": true, "license": "MIT", "optional": true, diff --git a/package.json b/package.json index 43f19ce1..d5ebdb04 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "node-gyp-build": "^4.8.1" }, "optionalDependencies": { - "@stoprocent/bluetooth-hci-socket": "^1.4.2" + "@stoprocent/bluetooth-hci-socket": "^1.4.3" }, "devDependencies": { "@commitlint/cli": "^19.3.0",