@stoprocent/bleno 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/FUNDING.yml ADDED
@@ -0,0 +1,15 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12
+ polar: # Replace with a single Polar username
13
+ buy_me_a_coffee: stoprocent # Replace with a single Buy Me a Coffee username
14
+ thanks_dev: # Replace with a single thanks.dev username
15
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
package/LICENSE CHANGED
@@ -1,20 +1,21 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2013 Sandeep Mistry
3
+ Copyright (c) 2024 Marek Serafin
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
11
 
12
12
  The above copyright notice and this permission notice shall be included in all
13
13
  copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,15 +1,52 @@
1
1
  # bleno
2
2
 
3
- [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sandeepmistry/bleno?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
-
3
+ [![GitHub forks](
4
+ https://img.shields.io/github/forks/stoprocent/bleno.svg?style=social&label=Fork&maxAge=2592000
5
+ )](
6
+ https://GitHub.com/stoprocent/bleno/network/
7
+ )
8
+ [![license](
9
+ https://img.shields.io/badge/license-MIT-0.svg
10
+ )](MIT)
11
+ [![NPM](
12
+ https://img.shields.io/npm/v/@stoprocent/bleno.svg
13
+ )](
14
+ https://www.npmjs.com/package/@stoprocent/bleno
15
+ )
5
16
 
6
17
  A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals.
7
18
 
8
- Need a BLE central module? See [noble](https://github.com/stoprocent/noble).
19
+ Need a BLE central module? See [@stoprocent/noble](https://github.com/stoprocent/noble).
20
+
21
+ ## About This Fork
22
+
23
+ This fork of `bleno` was created to introduce several key improvements and new features:
24
+
25
+ 1. **HCI UART Support**: This version enables HCI UART communication through the `@stoprocent/node-bluetooth-hci-socket` dependency, allowing more flexible use of Bluetooth devices across platforms.
26
+
27
+ 2. **macOS Native Bindings Fix**: I have fixed the native bindings for macOS, ensuring better compatibility and performance on Apple devices.
28
+
29
+ 3. **New Features**: A `setAddress` function has been added, allowing users to set the MAC address of the peripheral device. Additionally, I plan to add raw L2CAP channel support, enhancing low-level Bluetooth communication capabilities.
30
+
31
+ If you appreciate these enhancements and the continued development of this project, please consider supporting my work.
32
+
33
+ [![Buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/stoprocent)
34
+
35
+
36
+ ## Install
37
+
38
+ ```sh
39
+ npm install @stoprocent/bleno --save
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ```javascript
45
+ const bleno = require('@stoprocent/bleno');
46
+ ```
9
47
 
10
- __Note:__ Starting with version 0.6 bleno is basing on ES6 classes and supports Node.js 14.x and higher only. For older versions of Node.js use bleno 0.5.x.
48
+ See [examples folder](https://github.com/stoprocent/bleno/blob/master/examples) for code examples.
11
49
 
12
- __Note:__ macOS / Mac OS X, Linux, FreeBSD and Windows are currently the only supported OSes.
13
50
 
14
51
  ## Prerequisites
15
52
 
@@ -113,20 +150,6 @@ Make sure you have read and write permissions on the ```/dev/usb/*``` device tha
113
150
  * Compatible Bluetooth 4.0 USB adapter
114
151
  * [WinUSB](https://msdn.microsoft.com/en-ca/library/windows/hardware/ff540196(v=vs.85).aspx) driver setup for Bluetooth 4.0 USB adapter, using [Zadig tool](http://zadig.akeo.ie/)
115
152
 
116
- ## Install
117
-
118
- ```sh
119
- npm install bleno@npm:@stoprocent/bleno
120
- ```
121
-
122
- ## Usage
123
-
124
- ```javascript
125
- var bleno = require('bleno');
126
- ```
127
-
128
- See [examples folder](https://github.com/stoprocent/bleno/blob/master/examples) for code examples.
129
-
130
153
  ### Actions
131
154
 
132
155
  #### Set address
@@ -437,16 +460,3 @@ Advertising intervals must be between 20 ms to 10 s (10,000 ms).
437
460
  * LightBlue for [iOS](https://itunes.apple.com/us/app/lightblue/id557428110)/[OS X](https://itunes.apple.com/us/app/lightblue/id639944780)
438
461
  * [nRF Master Control Panel (BLE)](https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=en) for Android
439
462
  * [hcitool](http://linux.die.net/man/1/hcitool) and ```gatttool``` by [BlueZ](http://www.bluez.org) for Linux
440
-
441
-
442
- ## License
443
-
444
- Copyright (C) 2015 Sandeep Mistry <sandeep.mistry@gmail.com>
445
-
446
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
447
-
448
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
449
-
450
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
451
-
452
- [![Analytics](https://ga-beacon.appspot.com/UA-56089547-1/sandeepmistry/bleno?pixel)](https://github.com/igrigorik/ga-beacon)
@@ -1,18 +1,43 @@
1
1
  const bleno = require('../../with-custom-binding')({
2
2
  bindParams: {
3
3
  uart: {
4
- port: '/dev/tty...',
4
+ port: '/dev/tty...', // Specify the path to the UART device
5
5
  baudRate: 1000000
6
6
  }
7
7
  }
8
8
  });
9
9
 
10
+ function generateRandomBLEMacAddress () {
11
+ // Create an array to store 6 bytes for the MAC address
12
+ let macAddr = [];
13
+ // Generate 6 random bytes
14
+ for (let i = 0; i < 6; i++) {
15
+ // Generate a random byte between 0x00 and 0xFF
16
+ let randomByte = Math.floor(Math.random() * 256);
17
+ // Ensure the first byte is a locally administered unicast address
18
+ if (i === 0) {
19
+ randomByte = (randomByte & 0xFE) | 0x02; // Clear multicast bit and set locally administered bit
20
+ }
21
+ // Convert the byte to a two-character hexadecimal string
22
+ macAddr.push(randomByte.toString(16).padStart(2, '0'));
23
+ }
24
+ // Join the array into a MAC address string with colons
25
+ return macAddr.join(':');
26
+ }
27
+ let interval = null;
10
28
  bleno.on('stateChange', state => {
11
29
  console.log('on -> stateChange: ' + state);
12
30
 
13
31
  if (state === 'poweredOn') {
14
- bleno.setAddress('11:22:33:44:55:66');
15
- bleno.startAdvertisingIBeacon('a2744045-7004-4da9-8ed3-6d2d9a208c0a', 1234, 5678);
32
+ clearInterval(interval);
33
+ interval = setInterval(() => {
34
+ // Stop advertising
35
+ bleno.stopAdvertising();
36
+ // Set a random MAC address
37
+ bleno.setAddress(generateRandomBLEMacAddress());
38
+ // Start advertising as an iBeacon
39
+ bleno.startAdvertisingIBeacon('a2744045-7004-4da9-8ed3-6d2d9a208c0a', 1234, 5678);
40
+ }, 4000);
16
41
  } else {
17
42
  bleno.stopAdvertising();
18
43
  }
package/index.d.ts CHANGED
@@ -103,7 +103,7 @@ declare class PrimaryService {
103
103
  toString(): string;
104
104
  }
105
105
 
106
- interface Bleno extends NodeJS.EventEmitter {
106
+ export interface Bleno extends NodeJS.EventEmitter {
107
107
  readonly Characteristic: typeof Characteristic;
108
108
  readonly Descriptor: typeof Descriptor;
109
109
  readonly PrimaryService: typeof PrimaryService;
@@ -120,6 +120,8 @@ interface Bleno extends NodeJS.EventEmitter {
120
120
 
121
121
  disconnect(): void;
122
122
 
123
+ stop(): void;
124
+
123
125
  setAddress(address: string): void;
124
126
 
125
127
  setServices(services: ReadonlyArray<PrimaryService>, callback?: (arg: Error | undefined | null) => void): void;
package/lib/bleno.js CHANGED
@@ -211,6 +211,11 @@ class Bleno extends EventEmitter {
211
211
  this._bindings.disconnect();
212
212
  }
213
213
 
214
+ stop () {
215
+ debug('stop');
216
+ this._bindings.stop();
217
+ }
218
+
214
219
  updateRssi (callback) {
215
220
  if (typeof callback === 'function') {
216
221
  this.once('rssiUpdate', (rssi) => callback(null, rssi));
@@ -101,6 +101,12 @@ class BlenoBindings extends EventEmitter {
101
101
  this._hci.init();
102
102
  }
103
103
 
104
+ stop () {
105
+ this.stopAdvertising();
106
+ this.disconnect();
107
+ this._hci.stop();
108
+ }
109
+
104
110
  onStateChange (state) {
105
111
  if (this._state === state) {
106
112
  return;
@@ -210,9 +216,7 @@ class BlenoBindings extends EventEmitter {
210
216
  }
211
217
 
212
218
  onExit () {
213
- this._gap.stopAdvertising();
214
-
215
- this.disconnect();
219
+ this.stop();
216
220
  }
217
221
  }
218
222
 
@@ -116,6 +116,11 @@ class Hci extends EventEmitter {
116
116
  }
117
117
  }
118
118
 
119
+ stop() {
120
+ this._socket.removeAllListeners();
121
+ this._socket.stop();
122
+ }
123
+
119
124
  resetBuffers () {
120
125
  this._mainHandle = null;
121
126
  this._handleAclsInProgress = {};
@@ -228,6 +228,12 @@ Napi::Value BlenoMac::CleanUp(const Napi::CallbackInfo& info) {
228
228
  return Napi::Value();
229
229
  }
230
230
 
231
+ Napi::Value BlenoMac::Stop(const Napi::CallbackInfo& info) {
232
+ CHECK_MANAGER()
233
+ CleanUp(info);
234
+ return Napi::Value();
235
+ }
236
+
231
237
  Napi::Function BlenoMac::GetClass(Napi::Env env) {
232
238
  return DefineClass(env, "BlenoMac", {
233
239
  BlenoMac::InstanceMethod("init", &BlenoMac::Init),
@@ -248,6 +254,7 @@ Napi::Function BlenoMac::GetClass(Napi::Env env) {
248
254
  BlenoMac::InstanceMethod("readHandle", &BlenoMac::ReadValue),
249
255
  BlenoMac::InstanceMethod("writeHandle", &BlenoMac::WriteValue),
250
256
  BlenoMac::InstanceMethod("cleanUp", &BlenoMac::CleanUp),
257
+ BlenoMac::InstanceMethod("stop", &BlenoMac::Stop),
251
258
  });
252
259
  }
253
260
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoprocent/bleno",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -70,7 +70,7 @@
70
70
  "node-gyp-build": "^4.8.1"
71
71
  },
72
72
  "optionalDependencies": {
73
- "@stoprocent/bluetooth-hci-socket": "^1.4.0",
73
+ "@stoprocent/bluetooth-hci-socket": "^1.4.2",
74
74
  "bplist-parser": "0.3.2",
75
75
  "xpc-connect": "^3.0.0"
76
76
  },