Skip to content

Commit

Permalink
fix(hci): update hci socket to v1.4.1 and cleanups (#4)
Browse files Browse the repository at this point in the history
* chore(docs): readme and funding

* fix(hci): update hci socket to v1.4.1

* chore(example): update uart example to showcase setAddress

* chore(docs): cleanup

* chore(docs): readme updates

* chore(docs): readme update
  • Loading branch information
stoprocent authored Oct 1, 2024
1 parent 2013d2e commit 0b3464b
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 58 deletions.
15 changes: 15 additions & 0 deletions FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: stoprocent # Replace with a single Buy Me a Coffee username
thanks_dev: # Replace with a single thanks.dev username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
25 changes: 13 additions & 12 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 Sandeep Mistry
Copyright (c) 2024 Marek Serafin

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:
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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
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.
74 changes: 42 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
# bleno

[![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)

[![GitHub forks](
https://img.shields.io/github/forks/stoprocent/bleno.svg?style=social&label=Fork&maxAge=2592000
)](
https://GitHub.com/stoprocent/bleno/network/
)
[![license](
https://img.shields.io/badge/license-MIT-0.svg
)](MIT)
[![NPM](
https://img.shields.io/npm/v/@stoprocent/bleno.svg
)](
https://www.npmjs.com/package/@stoprocent/bleno
)

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals.

Need a BLE central module? See [noble](https://github.com/stoprocent/noble).
Need a BLE central module? See [@stoprocent/noble](https://github.com/stoprocent/noble).

## About This Fork

This fork of `bleno` was created to introduce several key improvements and new features:

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.

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 peripheral device. 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.

[![Buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/stoprocent)


## Install

```sh
npm install @stoprocent/bleno --save
```

## Usage

```javascript
const bleno = require('@stoprocent/bleno');
```

__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.
See [examples folder](https://github.com/stoprocent/bleno/blob/master/examples) for code examples.

__Note:__ macOS / Mac OS X, Linux, FreeBSD and Windows are currently the only supported OSes.

## Prerequisites

Expand Down Expand Up @@ -113,20 +150,6 @@ Make sure you have read and write permissions on the ```/dev/usb/*``` device tha
* Compatible Bluetooth 4.0 USB adapter
* [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/)

## Install

```sh
npm install bleno@npm:@stoprocent/bleno
```

## Usage

```javascript
var bleno = require('bleno');
```

See [examples folder](https://github.com/stoprocent/bleno/blob/master/examples) for code examples.

### Actions

#### Set address
Expand Down Expand Up @@ -437,16 +460,3 @@ Advertising intervals must be between 20 ms to 10 s (10,000 ms).
* LightBlue for [iOS](https://itunes.apple.com/us/app/lightblue/id557428110)/[OS X](https://itunes.apple.com/us/app/lightblue/id639944780)
* [nRF Master Control Panel (BLE)](https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=en) for Android
* [hcitool](http://linux.die.net/man/1/hcitool) and ```gatttool``` by [BlueZ](http://www.bluez.org) for Linux


## License

Copyright (C) 2015 Sandeep Mistry <[email protected]>

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.

[![Analytics](https://ga-beacon.appspot.com/UA-56089547-1/sandeepmistry/bleno?pixel)](https://github.com/igrigorik/ga-beacon)
2 changes: 1 addition & 1 deletion test-ibeacon.js → examples/test/test-ibeacon.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const bleno = require('./index');
const bleno = require('../../index');

console.log('bleno - iBeacon');

Expand Down
2 changes: 1 addition & 1 deletion test-matter.js → examples/test/test-matter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const bleno = require('./index');
const bleno = require('../../index');

let handshakeDone = false;

Expand Down
2 changes: 1 addition & 1 deletion test.js → examples/test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const bleno = require('./index');
const bleno = require('../../index');

const BlenoPrimaryService = bleno.PrimaryService;
const BlenoCharacteristic = bleno.Characteristic;
Expand Down
31 changes: 28 additions & 3 deletions examples/uart/main.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
const bleno = require('../../with-custom-binding')({
bindParams: {
uart: {
port: '/dev/tty...',
port: '/dev/tty...', // Specify the path to the UART device
baudRate: 1000000
}
}
});

function generateRandomBLEMacAddress () {
// Create an array to store 6 bytes for the MAC address
let macAddr = [];
// Generate 6 random bytes
for (let i = 0; i < 6; i++) {
// Generate a random byte between 0x00 and 0xFF
let randomByte = Math.floor(Math.random() * 256);
// Ensure the first byte is a locally administered unicast address
if (i === 0) {
randomByte = (randomByte & 0xFE) | 0x02; // Clear multicast bit and set locally administered bit
}
// Convert the byte to a two-character hexadecimal string
macAddr.push(randomByte.toString(16).padStart(2, '0'));
}
// Join the array into a MAC address string with colons
return macAddr.join(':');
}
let interval = null;
bleno.on('stateChange', state => {
console.log('on -> stateChange: ' + state);

if (state === 'poweredOn') {
bleno.setAddress('11:22:33:44:55:66');
bleno.startAdvertisingIBeacon('a2744045-7004-4da9-8ed3-6d2d9a208c0a', 1234, 5678);
clearInterval(interval);
interval = setInterval(() => {
// Stop advertising
bleno.stopAdvertising();
// Set a random MAC address
bleno.setAddress(generateRandomBLEMacAddress());
// Start advertising as an iBeacon
bleno.startAdvertisingIBeacon('a2744045-7004-4da9-8ed3-6d2d9a208c0a', 1234, 5678);
}, 4000);
} else {
bleno.stopAdvertising();
}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"node-gyp-build": "^4.8.1"
},
"optionalDependencies": {
"@stoprocent/bluetooth-hci-socket": "^1.4.0",
"@stoprocent/bluetooth-hci-socket": "^1.4.1",
"bplist-parser": "0.3.2",
"xpc-connect": "^3.0.0"
},
Expand Down

0 comments on commit 0b3464b

Please sign in to comment.