Skip to content

Commit 48b2428

Browse files
authored
Merge pull request #2 from ukBaz/indicate
Release v0.4.0
2 parents d9aad6f + d11e933 commit 48b2428

File tree

5 files changed

+90
-7
lines changed

5 files changed

+90
-7
lines changed

BLE_GATT/central.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def on_value_change(self, uuid, handler):
101101
"""
102102
uuid = uuid.casefold()
103103
if uuid in self.chrcs:
104-
if 'notify' not in self.chrcs[uuid].Flags:
104+
if all(('notify' not in self.chrcs[uuid].Flags,
105+
'indicate' not in self.chrcs[uuid].Flags)):
105106
raise NotImplementedError(
106107
f'Notifications are not implemented on {uuid}'
107108
)

README.rst

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
BLE GATT
33
========
44

5-
.. image:: ![Tests](https://github.com/ukBaz/BLE_GATT/workflows/Tests/badge.svg)
6-
:target: https://github.com/ukBaz/BLE_GATT/actions?query=workflow%3A%22Python+package%22
7-
:alt: Build Status
8-
95
.. image:: https://img.shields.io/pypi/l/bluezero.svg
106
:target: https://github.com/ukBaz/python-bluezero/blob/master/LICENSE
117
:alt: MIT License
@@ -14,6 +10,16 @@ BLE GATT
1410
:target: https://pypi.python.org/pypi/BLE-GATT/
1511
:alt: PyPI Version
1612

13+
..
14+
Work around to display GitHub actions svg
15+
.. raw:: html
16+
17+
<a href="https://github.com/ukBaz/BLE_GATT/actions?query=workflow%3ATests">
18+
<img src="https://github.com/ukBaz/BLE_GATT/workflows/Tests/badge.svg"
19+
type="image/svg+xml" alt="Build Status"/></a>
20+
<br>
21+
22+
1723
Python package for using BlueZ D-Bus API to create a device in the Central role
1824

1925
Goal
@@ -35,6 +41,55 @@ Install
3541
$ . venv_ble/bin/activate
3642
$ pip3 install BLE_GATT
3743
44+
tl;dr
45+
-----
46+
47+
Example of connecting and reading and writing without
48+
notifications or asynchronous data
49+
50+
.. code-block:: python
51+
52+
import BLE_GATT
53+
54+
ubit_address = 'E5:10:5E:37:11:2d'
55+
led_text = 'e95d93ee-251d-470a-a062-fa1922dfa9A8'
56+
led_matrix_state = 'e95d7b77-251d-470a-a062-fa1922dfa9a8'
57+
58+
ubit = BLE_GATT.Central(ubit_address)
59+
ubit.connect()
60+
ubit.char_write(led_text, b'test')
61+
ubit.char_write(led_matrix_state, [1, 2, 4, 8, 16])
62+
print(ubit.char_read(led_matrix_state))
63+
ubit.disconnect()
64+
65+
Example of connecting and interacting with characteristics asynchronously
66+
67+
.. code-block:: python
68+
69+
import BLE_GATT
70+
from gi.repository import GLib
71+
72+
ubit_address = 'E9:06:4D:45:FC:8D'
73+
uart_rx = '6e400003-b5a3-f393-e0a9-e50e24dcca9e'
74+
uart_tx = '6e400002-b5a3-f393-e0a9-e50e24dcca9e'
75+
76+
77+
def notify_handler(value):
78+
print(f"Received: {bytes(value).decode('UTF-8')}")
79+
80+
81+
def send_ping():
82+
print('sending: ping')
83+
ubit.char_write(uart_rx, b'ping\n')
84+
return True
85+
86+
87+
ubit = BLE_GATT.Central(ubit_address)
88+
ubit.connect()
89+
ubit.on_value_change(uart_tx, notify_handler)
90+
GLib.timeout_add_seconds(20, send_ping)
91+
ubit.wait_for_notifications()
92+
3893
3994
Basics of BLE
4095
-------------

examples/microbit_uart.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Example of connecting and getting notifications of value
3+
changes of characteristics
4+
"""
5+
import BLE_GATT
6+
from gi.repository import GLib
7+
8+
ubit_address = 'E9:06:4D:45:FC:8D'
9+
uart_rx = '6e400003-b5a3-f393-e0a9-e50e24dcca9e'
10+
uart_tx = '6e400002-b5a3-f393-e0a9-e50e24dcca9e'
11+
12+
13+
def notify_handler(value):
14+
print(f"Received: {bytes(value).decode('UTF-8')}")
15+
16+
17+
def send_ping():
18+
print('sending: ping')
19+
ubit.char_write(uart_rx, b'ping\n')
20+
return True
21+
22+
23+
ubit = BLE_GATT.Central(ubit_address)
24+
ubit.connect()
25+
ubit.on_value_change(uart_tx, notify_handler)
26+
GLib.timeout_add_seconds(20, send_ping)
27+
ubit.wait_for_notifications()

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.3.0
2+
current_version = 0.4.0
33
tag = True
44
tag_name = v{new_version}
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# Versions should comply with PEP440. For a discussion on single-sourcing
3030
# the version across setup.py and the project code, see
3131
# https://packaging.python.org/en/latest/single_source_version.html
32-
version='0.3.0',
32+
version='0.4.0',
3333

3434
description='Python library for Bluetooth Low Energy (BLE) Central on Linux',
3535
long_description=long_description,

0 commit comments

Comments
 (0)