2
2
BLE GATT
3
3
========
4
4
5
- .. image :: 
6
- :target: https://github.com/ukBaz/BLE_GATT/actions?query=workflow%3A%22Python+package%22
7
- :alt: Build Status
8
-
9
5
.. image :: https://img.shields.io/pypi/l/bluezero.svg
10
6
:target: https://github.com/ukBaz/python-bluezero/blob/master/LICENSE
11
7
:alt: MIT License
@@ -14,6 +10,16 @@ BLE GATT
14
10
:target: https://pypi.python.org/pypi/BLE-GATT/
15
11
:alt: PyPI Version
16
12
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
+
17
23
Python package for using BlueZ D-Bus API to create a device in the Central role
18
24
19
25
Goal
@@ -35,6 +41,55 @@ Install
35
41
$ . venv_ble/bin/activate
36
42
$ pip3 install BLE_GATT
37
43
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
+
38
93
39
94
Basics of BLE
40
95
-------------
0 commit comments