Python client for connecting to MbientLab's MetaWear boards
Python package for connecting to and using MbientLab’s MetaWear boards.
PyMetawear is meant to be a thin wrapper around the MetaWear C++ API, providing a more Pythonic interface. It has support for two different Python packages for Bluetooth Low Energy communication:
PyMetaWear can be run with Python 2 and 3.4 with both backends, but only with the pygatt backend for Python 3.5.
It is a Linux-only package right now! It can be built on Windows, given that Visual Studio Community 2015 has been installed first, but there is no working backend for Windows BLE yet.
$ pip install pymetawear
Currently, only the pygatt communication backend is installed by default. The other backend can be installed as extras:
$ pip install pymetawear[pybluez]
Debian requirements for pymetawear
Additional requirements for pybluez
Clone this repository and run
$ python setup.py build
to pull in the MetaWear C++ API submodule, build it and copy the Python wrappers from it to the PyMetaWear folder. This can also be achieved by running
$ pip install -e .
in the cloned repository’s root folder.
Available in the Github pages of this repository.
The MetaWear client can be used in two ways: either as Pythonic convenience class for handling a MetaWear board or as a simple communication client governed by the libmetawear C++ library.
Creating a client, and thus also setting up a Bluetooth connection to the MetaWear board, is equal for both the two usage profiles:
from pymetawear.client import MetaWearClient backend = 'pygatt' # Or 'pybluez' c = MetaWearClient('DD:3A:7D:4D:56:F0', backend)
An example: blinking with the LED lights can be done like this with the convenience methods:
pattern = c.led.load_preset_pattern('blink', repeat_count=10) c.led.write_pattern(pattern, 'g') c.led.play()
or like this using the raw libmetawear shared library:
from ctypes import byref from pymetawear import libmetawear from pymetawear.mbientlab.metawear.peripheral import Led pattern = Led.Pattern(repeat_count=10) libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), Led.PRESET_BLINK) libmetawear.mbl_mw_led_write_pattern(c.board, byref(pattern), Led.COLOR_GREEN) libmetawear.mbl_mw_led_play(c.board)
Actual addresses to your MetaWear board can be found by scanning, either directly with hcitool lescan or with the included discover_devices method:
from pymetawear.client import discover_devices out = discover_devices() print out [(u'DD:3A:7D:4D:56:F0', u'MetaWear'), (u'FF:50:35:82:3B:5A', u'MetaWear')]
See the examples folder for more examples on how to use the libmetawear library with this client.
All functionality of the MetaWear C++ API is able to be used using the PyMetaWear client, and some of the modules have had convenience methods added to simplify the use of them. Below are two list, one of modules which have had their convenience methods written and one of modules that are awaiting such focus.
|Completed Modules||Partial Modules||Unimplemented Modules|
- Using MetaWear-CppAPI version 0.7.10
- Sensor fusion module contributed from user m-georgi (#26).
- Fix to magnetometer power preset setting due to change in MetaWear-CppAPI (#25).
- Using MetaWear-CppAPI version 0.7.4
- Removed bluepy backend due to it not being fully functional.
- Refactored connection behaviour. Optional autoconnect via keyword.
- Unit test work started with Mock backend.
- Flake8 adaptations.
- Fix for logging bug (#22)
- New examples: Two client setup and complimentary filter sensor fusion (#23).
- Using MetaWear-CppAPI version 0.6.0
- Replaced print-logging with proper logging module usage.
- Removed 64-bit special handling that was no longer needed.
- Temperature Module
- Using Pygatt 3.0.0 (including PR from PyMetaWear contributors)
- Builds on Windows
- Corrections to make it distributable via PyPI.
- Using MetaWear-CppAPI version 0.5.22
- Changed building procedure to handle ARM processors
- Updated requirements to make pygatt default, all others extras
- Bluepy backend implemented and partially working
- BL interface selection for all backends
- Magnetometer module
- Barometer module
- Ambient Light module
- Modifying notification wrappers to accommodate Epoch value in the data.
- High speed sampling for accelerometer and gyroscope
- Updated MetaWear-CppAPI submodule version.
- Removed temporary build workaround.
- Critical fix for switch notifications.
- Updated MetaWear-CppAPI submodule version.
- Now using the new setup_metawear method.
- Restructured the IS_64_BIT usage which is still needed.
- Critical fix for timeout in pybluez/gattlib backend.
- Added Gyroscope module.
- Added soft reset method to client.
- Updated examples.
- Updated documentation.
- Cleanup of new modules sensor data parsing.
- Bug fix related to accelerometer module.
- Timeout parameter for client and backends.
- Major refactorisation into new module layout.
- New examples using the new module handling.
- Accelerometer convenience methods shows strange lag still.
- Critical fix for data signal subscription method.
- Setup.py handling of building made better,
- Documentation improved.
- Major refactoring: all BLE comm code practically moved to backends.
- Backend pybluez with gattlib now works well.
- Travis CI problems with Python 2.7 encoding led to that we are now building on 2.7.11
- Changed from using gattlib on its own to using pybluez with gattlib
- Travis CI and Coveralls
- Travis CI deploys documentation to gh-pages.
- Some documentation written.
- Convenience method for switch.
- Sphinx documentation added.
- Docstring updates.
- Refactoring in moving functionality back to client from backends.
- Enable BlueZ 4.X use with pygatt.
- Disconnect methods added.
- Example with switch button notification.
- Two backends: pygatt and gattlib
- pygatt backend can be fully initialize, i.e. handles notifications.
- gattlib backend cannot fully initialize, i.e. does not handles notifications.
- Fix to support Python 3
- Initial release
- Working communication, tested with very few API options.