Skip to content

Commit

Permalink
feat(bluetooth-classic): add scan time limit option
Browse files Browse the repository at this point in the history
Scanning for devices that aren't in range stresses the 2.4 GHz spectrum
for quite a while. With default settings it also barely left any time
for the integrated chips in Pis to communicate over WiFi. Resetting the
scan earlier should not have a notable impact on functionality for most
while hopefully decreasing the network performance hit.

Closes #179
  • Loading branch information
mKeRix committed Aug 16, 2020
1 parent d602c66 commit ae40009
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/integrations/bluetooth-classic.md
Expand Up @@ -83,6 +83,7 @@ If you don't have anything else running on the Pis this shouldn't be much of an
| `minRssi` | Number _or_ [detailed config](#minimum-rssi) | | Limits the RSSI at which a device is still reported if configured. Remember, the RSSI is the inverse of the sensor attribute distance, so for a cutoff at 10 you would configure -10. |
| `hciDeviceId` | Number | `0` | ID of the Bluetooth device to use for the inquiries, e.g. `0` to use `hci0`. |
| `interval` | Number | `6` | The interval at which the Bluetooth devices are queried in seconds. |
| `scanTimeLimit` | Number | `2` | The maximum time allowed for completing a device query in seconds. This should be set lower than the interval. |
| `timeoutCycles` | Number | `2` | The number of completed query cycles after which collected measurements are considered obsolete. The timeout in seconds is calculated as `max(addresses, clusterDevices) * interval * timeoutCycles`. |

### Minimum RSSI
Expand Down
Expand Up @@ -3,5 +3,6 @@ export class BluetoothClassicConfig {
minRssi?: number | { [address: string]: number };
hciDeviceId = 0;
interval = 6;
scanTimeLimit = 2;
timeoutCycles = 2;
}
Expand Up @@ -211,7 +211,7 @@ export class BluetoothClassicService extends KalmanFilterable(Object, 1.4, 1)
const output = await execPromise(
`hcitool -i hci${this.config.hciDeviceId} cc "${address}" && hcitool -i hci${this.config.hciDeviceId} rssi "${address}"`,
{
timeout: (this.config.interval - 0.5) * 1000,
timeout: this.config.scanTimeLimit * 1000,
killSignal: 'SIGKILL',
}
);
Expand All @@ -222,8 +222,8 @@ export class BluetoothClassicService extends KalmanFilterable(Object, 1.4, 1)
return matches?.length > 0 ? parseInt(matches[0], 10) : undefined;
} catch (e) {
if (e.signal === 'SIGKILL') {
this.logger.warn(
`Query of ${address} took too long, resetting hci${this.config.hciDeviceId}`
this.logger.debug(
`Query of ${address} reached scan time limit, resetting hci${this.config.hciDeviceId}`
);
this.healthIndicator.reportError();
this.resetHciDevice();
Expand Down

0 comments on commit ae40009

Please sign in to comment.