Skip to main content

Communicate with the EmBody device over BLE (bluetooth)

Project description

Embody BLE

PyPI Status Python Version License

Tests

pre-commit Black

Features

  • Connects to an EmBody device over BLE (Bluetooth)
  • Uses the EmBody protocol to communicate with the device
  • Integrates with the EmBody Protocol Codec project
  • Asynchronous send without having to wait for response
  • Synchronous send where response message is returned
  • Provides callback interfaces for incoming messages, response messages and connect/disconnect
  • Facade method to send/receive BLE messages directly
  • All methods and callbacks are threadsafe
  • Separate threads for send, receive and callback processing
  • Type safe code using mypy for type checking

Requirements

  • Python 3.9 (NOTE! Nordic's pc-ble-driver-py (and nrfutil) does not support 3.10 yet)
  • Access to private Aidee Health repositories on Github

Installation

You can install Embody BLE via pip:

$ pip install embody-ble

This adds embody-ble as a library, but also provides the CLI application with the same name.

Usage

A very basic example where you send a message request and get a response:

from embodyble.embodyble import EmbodyBle
from embodyserial.helpers import EmbodySendHelper

embody_ble = EmbodyBle()
send_helper = EmbodySendHelper(sender=embody_ble)
embody_ble.connect()
print(f"Serial no: {send_helper.get_serial_no()}")
embody_ble.shutdown()

If you want to see more of what happens under the hood, activate debug logging before setting up EmbodyBle:

import logging

logging.basicConfig(level=logging.DEBUG)

Using the application from the command line

The application also provides a CLI application that is automatically added to the path when installing via pip.

Once installed with pip, type:

embody-ble --help

To see which options are available.

Note The serial port is automatically detected, but can be overridden by using the --device option.

Example - List all available EmBody devices

embody-ble --list-candidates

Example - List all attribute values

embody-ble --get-all

Example - Get serial no of device

embody-ble --get serialno

Example - List files over serial port

embody-ble --list-files

Example - Set time current time (UTC)

embody-ble --set-time

Troubleshooting

I get a segmentation fault on Mac

As of writing, you need to use the official Python release for Mac. Using brew's version does not work. For more, look at the README for Nordic's pc-ble-driver-py

Suggested setup, using a virtual environment:

# create virtual environment with official Python version
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -m venv .venv
# activate virtual environment
source .venv/bin/activate
# install embody-ble
pip install embody-ble
# test installation
embody-ble --help

If you're using a Mac M1 or M2 with an ARM processor, look at this thread for tips.

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

embody_ble-1.0.11.tar.gz (13.3 kB view hashes)

Uploaded Source

Built Distribution

embody_ble-1.0.11-py3-none-any.whl (12.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page