Package: btzen
BTZen is a library to asynchronously access Bluetooth devices using Python
language. It provides simple API over complex D-Bus Bluez interface.FeaturesThe main features of BTZen areConnect and access multiple Bluetooth devices in parallel with Python
asynchronous coroutines.GATT notification interface integrated into main API of the library.Automatic reconnections to devices.Access to serial devices implementing Stollmann (Telit) protocol.Support for devices, which do not follow the Bluetooth specification
fully like SensorTag (CC2650STK) or Thingy:52.Support for Bluez managed interfaces of devices, i.e. battery level.Allow to implement support for new devices easily.The library can be used with any Bluetooth Smart device. It was tested withSensorTag (CC2650STK) to read temperature, pressure, humidity, light,
accelerometer data and state of the buttons.Thingy:52 to read temperature, pressure, humidity, light data and state
of the button.Mi Smart Scale to read weight data.OSTC dive computer to read serial device data using Stollmann (Telit)
protocol.The library is tested with defaultasyncioevent loop and its drop-in
replacementuvloop. Use ofuvloopincreases performance of the library.The scripts inscriptsdirectory demonstrate reading data from various
devices.NOTE: The first version of SensorTag (CC2541DK) is not supported at the
moment. If you still own the device and would like it to be supported,
pleaseraise an issue.API ChangesPlease note that since version 0.6.0 the API changed. The benefits aresupport different makes of devices with single APIit is much easier to implement functionality for new devicesshutting down of BTZen connection sessions is more reliableIf pre-0.6.0 version of BTZen is required, then use appropriate versioning
in installation requirements of your project.DocumentationThis project’s documentation is lacking at the moment. Some useful tips
might be found in this README file and files athttps://github.com/wrobell/btzen/tree/master/docInstallationUsepipto install BTZen library (Cython needs to be installed first),
for example:pip install --user cython
pip install --user btzenBTZen uses experimental API of Bluez adapter interface to connect to
Bluetooth devices. Thebluetoothddaemon has to be started with
experimental option on. This can be permanently achieved by settingExperimentaltotruein/etc/bluez/main.conffile.ChangeAutoEnableoption to true in/etc/bluetooth/main.confto
automate powering up of Bluetooth controllers. Otherwise a controller might
need to be switched on manually withbluetoothctltool. BTZen library
does not perform this operation.Connection ManagementBTZen usesConnectDevicemethod of Bluez adapter interface to discover
and connect to Bluetooth devices. MAC address of a device needs to be known
in order to connect.BTZen connection manager allows to connect and disconnect Bluetooth devices
without restarting of an application. If an application is reading data
from multiple Bluetooth devices, the application can continue working if,
for example, a sensor requires battery change.Please notewhen trying to connect to a device using BTZen library, do not start scan
with other programs, i.e.bluetoothctlif a device is disconnected with an external program, the external program
has to be used to reconnectObtaining MAC AddressIf Bluetooth device MAC address is not knownStartbluetoothctl.Start scan.Save discovered MAC address.Optionally, remove device withremovecommand ofbluetoothctlutility.Start BTZen based application using the discovered MAC address.PerformanceThe library enables programmers to communicate with mutliple devices in
parallel without using threads. This avoids context switching of threads
and minimizes memory requirements, which makes BTZen more efficient than
other, similar libraries. To keep the library as fast as possible, Cython
is used to access Bluez D-Bus API. BTZen can be used withuvloopfor even
more increased performance of an application.Support for GATT notification interface allows efficient use of Bluetooth
devices. For example, data from sensors like accelerometers can be read
only when sensor wakes up and transmits data after sensor has been moved.
This limits amount of transferred data and avoids draining battery of the
sensor, which will happen if data is polled at regular, short intervals.RequirementsBTZen library requires the following software componentsPython 3.11bluez 5.68sd-bus(kart ofsystemd)Cython 3.0.0LicenseBTZen library is licensed under terms of GPL license, version 3, seeCOPYINGfile for details.