Skip to content

Commit

Permalink
Tidy up documentation, add scanning example code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Harvey committed Dec 24, 2015
1 parent f9fcaef commit 759e8a6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/notifications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ In ``bluepy``, notifications are processed by creating a "delegate" object and
registering it with the ``Peripheral``. A method in the delegate is called whenever
a notification is received from the peripheral, as shown below:

.. function:: handleNotification(cHandle, data):
.. function:: handleNotification(cHandle, data)

Called when a notification has been received from a ``Peripheral``. Normally
you will call the peripheral's ``waitForNotifications()`` method to allow this,
Expand Down
8 changes: 4 additions & 4 deletions docs/peripheral.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Constructor
.. function:: Peripheral([deviceAddress=None, [addrType=ADDR_TYPE_PUBLIC [, iface=None]]])

If *deviceAddress* is not ``None``, creates a ``Peripheral`` object and makes a connection
to the device indicated by *deviceAddress* (which should be a string comprising six hex
bytes separated by colons, e.g. ``"11:22:33:ab:cd:ed"``).
to the device indicated by *deviceAddress*. *deviceAddress* should be a string comprising six hex
bytes separated by colons, e.g. ``"11:22:33:ab:cd:ed"``.

If *deviceAddress* is ``None``, creates an un-connected ``Peripheral`` object. You must call the ``connect()`` method on this object (passing it a device address) before it will be usable.

Expand All @@ -22,7 +22,7 @@ Constructor
details.

The *iface* parameter allows the Bluetooth interface on which to make the connection to be set.
On Linux, ``0`` means */dev/hci0*, ``1`` means */dev/hci1* and so on.
On Linux, 0 means */dev/hci0*, 1 means */dev/hci1* and so on.

*deviceAddress* may also be a ``ScanEntry`` object. In this case the device address,
address type, and interface number are all taken from the ``ScanEntry`` values, and
Expand Down Expand Up @@ -119,7 +119,7 @@ Instance Methods
If *withResponse* is true, will await confirmation that the write was successful
from the device.

.. function:: readCharacteristic(handle):
.. function:: readCharacteristic(handle)

Reads the current value of the characteristic identified by *handle*. This is
useful if you know the handle for the characteristic but do not have a suitable
Expand Down
40 changes: 39 additions & 1 deletion docs/scanner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,54 @@ Instance Methods
discovered during that time.

*scan()* is equivalent to calling the *clear()*, *start()*,
*process()* and *stop()* methods.
*process()* and *stop()* methods in order.

.. function:: clear()

Clears the current set of discovered devices.

.. function:: start()

Enables reception of advertising broadcasts from peripherals.
Should be called before calling *process()*.

.. function:: process ( [timeout = 10] )

Waits for advertising broadcasts and calls the *delegate* object
when they are received. Returns after the given *timeout* period
in seconds. This may be called multiple times (between calls to
*start()* and *stop()* ).

.. function:: stop()

Disables reception of advertising broadcasts. Should be called after
*process()* has returned.


Sample code
-----------

Basic code to run a LE device scan follows this example::

from btle import Scanner, DefaultDelegate

class ScanDelegate(DefaultDelegate):
def __init__(self):
DefaultDelegate.__init__(self)

def handleDiscovery(self, dev, isNewDev, isNewData):
if isNewDev:
print "Discovered device", dev.addr
elif isNewData:
print "Received new data from", dev.addr
devices = scanner.scan(10.0)

for dev in devices:
print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.atype, dev.rssi)
for (adtype, desc, value) in dev.getScanData():
print " %s = %s" % (desc, value)

See the documentation for ``ScanEntry`` for the information available via the *dev*
parameter passed to the delegate.

0 comments on commit 759e8a6

Please sign in to comment.