Discovering addresses to MetaWear boards

If you do not know the address of your MetaWear board, it can be found by performing a scan.

>>> from pymetawear.client import discover_devices
>>> discover_devices()
[(u'DD:3A:7D:4D:56:F0', u'MetaWear'), (u'FF:50:35:82:3B:5A', u'MetaWear')]

On Linux, the discover_devices() function uses the hcitool application, provided by the BlueZ bluetooth application. See docstring below for more details about privileges using hcitool from Python.

One can run the discover_devices_warble() to use the PyWarble methods, but it requires sudo privileges on Linux.

There is a convenience method named select_device() as well, which displays a list of devices to choose from.

API

Performing BLE scans

copyright:2016-11-29 by hbldh <henrik.blidh@nedomkull.com>
pymetawear.discover.discover_devices(timeout=5)[source]

Run a BLE scan to discover nearby devices.

Parameters:timeout (int) – Duration of scanning.
Returns:List of tuples with (address, name).
Return type:list
pymetawear.discover.discover_devices_hcitool(timeout=5)[source]

Discover Bluetooth Low Energy Devices nearby on Linux

Using hcitool from Bluez in subprocess, which requires root privileges. However, hcitool can be allowed to do scan without elevated permission.

Install linux capabilities manipulation tools:

$ sudo apt-get install libcap2-bin

Sets the missing capabilities on the executable quite like the setuid bit:

$ sudo setcap 'cap_net_raw,cap_net_admin+eip' `which hcitool`

References:

Parameters:timeout (int) – Duration of scanning.
Returns:List of tuples with (address, name).
Return type:list
pymetawear.discover.discover_devices_warble(timeout=5.0)[source]

Use PyWarble’s discovery method.

Requires elevated access in Linux?

Parameters:timeout (int) – Duration of scanning.
Returns:List of tuples with (address, name).
Return type:list
pymetawear.discover.select_device(timeout=3)[source]

Run discover_devices and display a list to select from.

Parameters:timeout (int) – Duration of scanning.
Returns:The selected device’s address.
Return type:str