Python client using C++ API
Hello,
I just wanted to make you aware of the Python package that I uploaded to Github today: https://github.com/hbldh/pymetawear
It is a Metawear communication client written in Python, using the C++ API library.
It is in a early stage of development and testing, but I have gotten it to connect and blink LEDs on both R Pro and C boards; in my book a decent state after the two days I have hitherto dedicated to it. I have two projects that I want to use the MetaWear boards for so I think I will continue to develop it for some time to come.
This discussion has been closed.
Comments
mbl_mw_metawearboard_tear_down(board) mbl_mw_metawearboard_free(board)
Is there any need for the Debug module's
mbl_mw_debug_disconnect
function in this context? When should that be used?A related question:
Do I have to manually unsubscribe from all notifications prior to disconnect, or will these be removed by itself. In the
mbl_mw_metawearboard_tear_down
functon I see removal of DataProcessors, Timers, Events, Logging but nothing about notifications. Is that done here? Can I use thembl_mw_debug_reset
to accomplish that in worst cases?mbl_mw_debug_disconnect
is not to be used in this case.mbl_mw_metawearboard_tear_down
andmbl_mw_metawearboard_free
functions are only needed if your app is a long running process that will be interacting with many boards and needs some memory management. If it's just a simple script that issues a few commands, you won't need either of them i.e. a script that turn son the LED.mbl_mw_debug_reset
only issues the reset command; it does not modify the API state. Functions in the debug header file are meant for helping you debug / develop on your board and are not meant to be used in production code.Do you know if this should be able to be installed on Debian Jessie? I'm on a Raspberry Pi 3 and attempted to install it, but got some errors (apologies, away from the pi at the moment, so cannot post the errors) after the gatttools setup.py process.
I am attempting to add this to a python 3 program which uses OpenCV and the Pi Camera.
Thanks,
Luis
Discovering nearby Bluetooth Low Energy devices...
Traceback (most recent call last):
File "battery.py", line 22, in <module>
address = scan_and_select_le_device()
File "/home/pi/pymetawear/examples/discover.py", line 26, in scan_and_select_le_device
ble_devices = discover_devices(timeout=timeout)
File "/home/pi/.virtualenvs/cv/local/lib/python3.4/site-packages/pymetawear-0.5.0.dev3-py3.4.egg/pymetawear/client.py", line 74, in discover_devices
raise PyMetaWearException("Missing capabilites for hcitool!")
pymetawear.exceptions.PyMetaWearException: Missing capabilites for hcitool!
In this commit, there is a functions.py file that seems to include several methods for working with neopixels such as this and this. In theory I should be able to use these to control the neopixels. I've written a small python script and it seems communication is fine. Next, I'll hook up some pixels!
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from ctypes import byref
from pymetawear import libmetawear
from pymetawear.client import MetaWearClient
#just using one metawear
c = MetaWearClient('XX:XX:XX:XX:XX:XX, 'pygatt', debug=True)
print("New client created: {0}".format(c))
#args board, strand, pin, #pixels, color order
libmetawear.mbl_mw_neopixel_init_slow_strand(c.board, 0, 0, 1, 0)
#args board, strand, pixel id, r, g, b
libmetawear.mbl_mw_neopixel_set_color(c.board, 0, 0, 100, 0, 100)
print('about to disconnect')
c.disconnect()
mbl_mw_datasignal_log
?