forked from mickiebyrd/bluepy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work in progress, docs fixes + additions for scanning
- Loading branch information
Ian Harvey
committed
Dec 24, 2015
1 parent
aec8cf6
commit f9fcaef
Showing
6 changed files
with
211 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.. _delegate: | ||
|
||
The ``DefaultDelegate`` class | ||
============================= | ||
|
||
``bluepy`` functions which receive Bluetooth messages asynchronously - | ||
such as notifications, indications, and advertising data - pass this information | ||
to the user by calling methods on a 'delegate' object. | ||
|
||
To be useful, the delegate object will be from a class created by the user. | ||
Bluepy's ``DefaultDelegate`` is a base class for this - you should override | ||
some or all of the methods here with your own application-specific code. | ||
|
||
Constructor | ||
----------- | ||
|
||
.. function:: DefaultDelegate() | ||
|
||
Initialises the object instance. | ||
|
||
|
||
Instance Methods | ||
---------------- | ||
|
||
.. py:method:: handleNotification(cHandle, data) | ||
Called when a notification or indication is received from a connected | ||
``Peripheral`` object. *cHandle* is the (integer) handle for the | ||
characteristic - this can be used to distinguish between notifications | ||
from multiple sources on the same peripheral. *data* is the characteristic | ||
data (a ``str`` type on Python 2.x, and ``bytes`` on 3.x). | ||
|
||
.. py:method:: handleScan(scanEntry, isNewDev, isNewData) | ||
Called when advertising data is received from an LE device while a | ||
``Scanner`` object is active. *scanEntry* contains device information | ||
and advertising data - see the ``ScanEntry`` class for details. *isNewDev* | ||
is ``True`` if the device (as identified by its MAC address) has not been | ||
seen before by the scanner, and ``False`` otherwise. *isNewData* is ``True`` | ||
if new or updated advertising data is available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ Contents: | |
:maxdepth: 2 | ||
|
||
peripheral | ||
scanner | ||
scanentry | ||
delegate | ||
uuid | ||
service | ||
characteristic | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
.. _scanentry: | ||
|
||
The ``ScanEntry`` class | ||
======================= | ||
|
||
A ``ScanEntry`` object contains information received from a Bluetooth LE | ||
device received during ``Scanner`` operation. This includes parameters | ||
needed to connect to the device (MAC address, address type), and | ||
advertising data (such as its name or available services) supplied in | ||
the device's broadcasts. | ||
|
||
Constructor | ||
----------- | ||
|
||
``ScanEntry`` objects are created by the ``Scanner`` class, and should not | ||
be created by the user. | ||
|
||
Instance Methods | ||
---------------- | ||
|
||
.. py:method:: getDescription(adtype) | ||
Returns a human-readable description of the advertising data 'type' | ||
code *adtype*. For instance, an *adtype* value of 9 would return the | ||
string ``"Complete Local Name"``. See the Generic Access Profile | ||
assigned numbers at https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile | ||
for a complete list. | ||
|
||
.. py:method:: getValueText(adtype) | ||
Returns a human-readable string representation of the advertising data | ||
for code *adtype*. Values such as the 'local name' are returned as | ||
strings directly; other values are converted to hex strings. If the | ||
requested data is not available, ``None`` is returned. | ||
|
||
.. py:method:: getScanData() | ||
Returns a list of tuples *(adtype, description, value)* containing the | ||
AD type code, human-readable description and value (as reported by | ||
``getDescription()`` and ``getValueText()``) for all available advertising | ||
data items. | ||
|
||
Properties | ||
---------- | ||
|
||
All the properties listed below are read-only. | ||
|
||
.. py:attribute:: addr | ||
Device MAC address (as a hex string separated by colons). | ||
|
||
.. py:attribute:: addrType | ||
Device address type - one of *ADDR_TYPE_PUBLIC* or *ADDR_TYPE_RANDOM*. | ||
|
||
.. py:attribute:: rssi | ||
Received Signal Strength Indication for the last received broadcast from the | ||
device. This is an integer value measured in dB, where 0 dB is the maximum | ||
(theoretical) signal strength, and more negative numbers indicate a weaker signal. | ||
|
||
.. py:attribute:: connectable | ||
Boolean value - ``True`` if the device supports connections, and ``False`` | ||
otherwise (typically used for advertising 'beacons'). | ||
|
||
.. py:attribute:: updateCount | ||
Integer count of the number of advertising packets received from the device | ||
so far (since *clear()* was called on the ``Scanner`` object which found it). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.. _scanner: | ||
|
||
The ``Scanner`` class | ||
===================== | ||
|
||
A ``Scanner`` object is used to scan for LE devices which are broadcasting | ||
advertising data. In most situations this will give a set of devices which | ||
are available for connection. (Note, however, that Bluetooth LE devices may | ||
accept connections without broadcasting advertising data, or may broadcast | ||
advertising data but may not accept connections). | ||
|
||
|
||
Constructor | ||
----------- | ||
|
||
.. function:: Scanner( [index=0] ) | ||
|
||
Creates and initialises a new scanner object. *index* identifies the | ||
Bluetooth interface to use (where 0 is **/dev/hci0** etc). Scanning | ||
does not start until the *start()* or *scan()* methods are called - | ||
see below for details. | ||
|
||
Instance Methods | ||
---------------- | ||
|
||
.. function:: withDelegate(delegate) | ||
|
||
Stores a reference to a *delegate* object, which receives callbacks | ||
when broadcasts from devices are received. See the documentation for | ||
``DefaultDelegate`` for details. | ||
|
||
.. function:: scan( [timeout = 10] ) | ||
|
||
Scans for devices for the given *timeout* in seconds. During this | ||
period, callbacks to the *delegate* object will be called. When the | ||
timeout ends, scanning will stop and the method will return a list | ||
(or a *view* on Python 3.x) of ``ScanEntry`` objects for all devices | ||
discovered during that time. | ||
|
||
*scan()* is equivalent to calling the *clear()*, *start()*, | ||
*process()* and *stop()* methods. | ||
|
||
.. function:: clear() | ||
|
||
Clears the current set of discovered devices. | ||
|
||
.. function:: start() | ||
|
||
.. function:: process ( [timeout = 10] ) | ||
|
||
.. function:: stop() | ||
|
||
|