Skip to content

Commit

Permalink
feat(bluetooth): allow BLE and Classic to run on same adapter
Browse files Browse the repository at this point in the history
BLE scans will be done inbetween Classic inquiries.

Closes #209
  • Loading branch information
mKeRix committed Oct 17, 2020
1 parent dd464c9 commit b0c0671
Show file tree
Hide file tree
Showing 17 changed files with 588 additions and 363 deletions.
28 changes: 0 additions & 28 deletions docs/integrations/bluetooth-classic.md
Expand Up @@ -2,12 +2,6 @@

**Integration Key:** `bluetoothClassic`

::: warning

Using this together with [Bluetooth Low Energy](./bluetooth-low-energy) requires multiple Bluetooth adapters.

:::

The Bluetooth Classic integration can detect the location of any Bluetooth device within the home. It does this by sending out connection requests to the device addresses you configure on rotation and then checking the signal strength of the response. The configured Bluetooth devices do not need to be paired with your machines running room-assistant.

The integration has been tested to work great with the Apple Watch. You may see a minor hit on the battery life of the Bluetooth devices when enabling this.
Expand Down Expand Up @@ -131,25 +125,3 @@ bluetoothClassic:
```

:::

::: details Multiple Bluetooth Integrations Example Config

`hciDeviceId` can be used to choose a different Bluetooth adapter than the default one. Use hciconfig from the command line to see all available Bluetooth adapters. When using Bluetooth Classic and Bluetooth Low Energy at the same time you need to specify different IDs for these integrations.

```yaml
global:
integrations:
- bluetoothClassic
- bluetoothLowEnergy
bluetoothClassic:
hciDeviceId: 0
addresses:
- '08:05:90:ed:3b:60'
- '77:50:fb:4d:ab:70'
bluetoothLowEnergy:
hciDeviceId: 1
whitelist:
- 7750fb4dab70
- 2f234454cf6d4a0fadf2f4911ba9ffa6-1-2
```
:::
14 changes: 7 additions & 7 deletions docs/integrations/bluetooth-low-energy.md
Expand Up @@ -2,18 +2,18 @@

**Integration Key:** `bluetoothLowEnergy`

::: warning

Using this together with [Bluetooth Classic](./bluetooth-classic) requires multiple Bluetooth adapters.

:::

The Bluetooth Low Energy (BLE) integration scans for advertisement packets that other devices, like iBeacon or Bluetooth tags, emit. You can use any of the many different BLE tags or smart armbands out there, as long as they send out a constant ID. An example would be the [RadBeacon Chip](https://store.radiusnetworks.com/collections/all/products/radbeacon-chip) or the [iB001W](https://www.beaconzone.co.uk/iB001W?search=iB001W). You can use Google or your favorite tech hardware store to find many other products like them that would also work.

The integration calculates an estimated distance in meters for all advertisements it receives and uses that to update the current location of the device. Since there are many factors at play these estimations are not exact measurements, especially once there are obstructions between the BLE device and room-assistant instance. The best accuracy can be achieved with properly configured iBeacons. The distance value is smoothed using a [Kalman filter](https://en.wikipedia.org/wiki/Kalman_filter) to limit the impact of measurement noise.

## Requirements

::: tip

Using this together with [Bluetooth Classic](./bluetooth-classic) on the same adapter works, but will slightly degrade the performance. If you encounter issues you can try to run to run the integrations from different HCI devices.

:::

This integration requires a BLE capable Bluetooth adapter. Most modern boards like the Raspberry Pi Zero W have an integrated adapter that is suitable. Any Bluetooth USB stick with BLE and Linux support should also work.

### Running with NodeJS
Expand Down Expand Up @@ -87,7 +87,7 @@ bluetoothLowEnergy:

::: details Multiple Bluetooth Integrations Example Config

`hciDeviceId` can be used to choose a different Bluetooth adapter than the default one. Use hciconfig from the command line to see all available Bluetooth adapters. When using Bluetooth Classic and Bluetooth Low Energy at the same time you need to specify different IDs for these integrations.
`hciDeviceId` can be used to choose a different Bluetooth adapter than the default one. Use hciconfig from the command line to see all available Bluetooth adapters. This may be useful when using Bluetooth Classic and Bluetooth Low Energy at the same time, as you could then have BLE passive scanning enabled at all times instead of just when no Bluetooth Classic inquiry is running.

```yaml
global:
Expand Down
4 changes: 1 addition & 3 deletions docs/integrations/xiaomi-mi.md
Expand Up @@ -4,9 +4,7 @@

::: warning

Using this together with [Bluetooth Classic](./bluetooth-classic) requires multiple Bluetooth adapters.
Using this together with [Bluetooth Low Energy](./bluetooth-low-energy)
requires that the hciDeviceId settings of both integrations are the same value.
Using this together with [Bluetooth Low Energy](./bluetooth-low-energy) requires that the hciDeviceId settings of both integrations are the same value.

:::

Expand Down
Expand Up @@ -3,16 +3,15 @@ import { BluetoothClassicService } from './bluetooth-classic.service';
import { ConfigModule } from '../../config/config.module';
import { EntitiesModule } from '../../entities/entities.module';
import { ClusterModule } from '../../cluster/cluster.module';
import { BluetoothClassicHealthIndicator } from './bluetooth-classic.health';
import { StatusModule } from '../../status/status.module';
import BluetoothModule from '../bluetooth/bluetooth.module';

@Module({})
export default class BluetoothClassicModule {
static forRoot(): DynamicModule {
return {
module: BluetoothClassicModule,
imports: [ConfigModule, EntitiesModule, ClusterModule, StatusModule],
providers: [BluetoothClassicService, BluetoothClassicHealthIndicator],
imports: [BluetoothModule, ConfigModule, EntitiesModule, ClusterModule],
providers: [BluetoothClassicService],
};
}
}

0 comments on commit b0c0671

Please sign in to comment.