Bluetooth Client Manager Service
  • Python 98.8%
  • Cap'n Proto 0.8%
  • Scheme 0.4%
Find a file
2024-05-10 15:16:19 +01:00
bcms deprecated --use_device_identity; make API init more robust; use Sentry 2024-05-10 15:16:19 +01:00
docs add license, cleanup readme, add systemd service example 2023-12-14 09:37:39 +00:00
tests move some stuff to shared library 2024-02-16 20:35:25 +00:00
.gitignore tweaks related to scan and submission interval; revision of ble notification 2023-12-13 16:12:59 +00:00
.gitlab-ci.yml fix ci script to ignore warning 2023-12-11 14:42:41 +00:00
CHANGELOG.md deprecated --use_device_identity; make API init more robust; use Sentry 2024-05-10 15:16:19 +01:00
CONTRIBUTE.md deprecated --use_device_identity; make API init more robust; use Sentry 2024-05-10 15:16:19 +01:00
LICENSE add license, cleanup readme, add systemd service example 2023-12-14 09:37:39 +00:00
manifest.scm default to disable notifications; tweaks 2024-03-04 12:04:29 +00:00
README.md deprecated --use_device_identity; make API init more robust; use Sentry 2024-05-10 15:16:19 +01:00
setup.py deprecated --use_device_identity; make API init more robust; use Sentry 2024-05-10 15:16:19 +01:00

Bluetooth Client Manager Service

Features

  • Track, Pair, Unpair devices
  • Collect BLE data (passive & active)
  • Submit data to API

Defaults:

  • Bluetooth scan for 5s
  • IOT API data submission every 30s
  • Clear IOT data cache every 180s
  • RPC port: 4567

Usage

Daemon

Run the daemon:

bcms-daemon --debug True

All arguments:

  • --debug: Enable debug logging
  • --notify: Display notifications
  • --username USERNAME: username for notifications
  • --sleep: sleep time between scans
  • --sleep-data: sleep time between data submissions
  • --use_device_identity: use device identity for authentication (and submit data to API)
  • --application_identifier: identify remote server to register ble devices with and log to. To be used with --use_device_identity

To pair devices with PIN-prompt, running this in the background can be useful.:

bt-agent --capability=NoInputNoOutput

CLI

Run the CLI:

$ bcms --help
usage: bcms [-h] [--address ADDRESS] [--only_approved | --no-only_approved] [--mode MODE]
            {list,approve,remove,mode,set_mode,pair,unpair,is_paired}

BCMS Client

positional arguments:
  {list,approve,remove,mode,set_mode,pair,unpair,is_paired}

options:
  -h, --help            show this help message and exit
  --address ADDRESS
  --only_approved, --no-only_approved
  --mode MODE

For example, to list devices:

bcms list

To request pairing:

bcms pair --address 00:11:22:33:44:55

Daemon CLI

Run the daemon CLI:

$ bcms-daemon --help
usage: bcms-daemon [-h] [-u USERNAME] [-n NOTIFY] [-s SLEEP] [-sd SLEEP_DATA] [-di USE_DEVICE_IDENTITY]
                   [-appid APPLICATION_IDENTIFIER] [-d DEBUG]

Bluetooth Client Manager Service Python companion script to fetch data from bluetooth device and write to file.

options:
  -h, --help            show this help message and exit
  -u USERNAME, --username USERNAME
                        Trigger notification for specific username
  -n NOTIFY, --notify NOTIFY
                        Trigger notification
  -s SLEEP, --sleep SLEEP
                        Sleep time in seconds between checks
  -sd SLEEP_DATA, --sleep-data SLEEP_DATA
                        Sleep time in seconds between API submission
  -appid APPLICATION_IDENTIFIER, --application_identifier APPLICATION_IDENTIFIER
                        Identify remote server to register ble devices with and log to.
  -d DEBUG, --debug DEBUG
                        Display more verbose debug logs

RPC

The CLI relies on a RPC interface which you can use, too:

interface BCMS {
    list     @0 (onlyApproved :Bool) -> (devices :List(BCMSDeviceInfo), errors :List(Text));
    approve  @1 (address :Text) -> (status :Bool, errors :List(Text));
    remove   @2 (address :Text) -> (status :Bool, errors :List(Text));
    mode     @3 () -> (mode :BCMSWorkingMode);
    setMode  @4 (mode :BCMSWorkingMode) -> (status: Bool, errors :List(Text));
    pair     @5 (address :Text) -> (status :Bool, errors :List(Text));
    unpair   @6 (address :Text) -> (status :Bool, errors :List(Text));
    isPaired @7 (address :Text) -> (status :Bool, errors :List(Text));
}

Checkout bcms/rpc/bcms.capnp for more details.

Spec

IOT data is submitted to the backend like so:

{
    "data": [
        {
            "iotDeviceId": "cd553938-8960-4e70-864a-a7fba06578c0",
            "dataType": "heart_rate",
            "data": [
                {
                    "timestamp": "1642694304",
                    "data": {
                        "rate": "67"
                    }
                },
                {
                    "timestamp": "1642694364",
                    "data": {
                        "rate": "66"
                    }
                }
            ]
        },
        {
            "iotDeviceId": "cd553938-8960-4e70-864a-a7fba06578c0",
            "dataType": "battery_level",
            "data": [
                {
                    "timestamp": "1642694364",
                    "data": {
                        "level": "22"
                    }
                }
            ]
        }
    ]
}