@@ -70,7 +70,7 @@ Alternatively, install the `aioble` package, which will install everything.
70
70
Usage
71
71
-----
72
72
73
- Passive scan for nearby devices for 5 seconds: (Observer)
73
+ #### Passive scan for nearby devices for 5 seconds: (Observer)
74
74
75
75
``` py
76
76
async with aioble.scan(duration_ms = 5000 ) as scanner:
@@ -87,7 +87,7 @@ async with aioble.scan(duration_ms=5000, interval_us=30000, window_us=30000, act
87
87
print (result, result.name(), result.rssi, result.services())
88
88
```
89
89
90
- Connect to a peripheral device: (Central)
90
+ #### Connect to a peripheral device: (Central)
91
91
92
92
``` py
93
93
# Either from scan result
@@ -101,7 +101,7 @@ except asyncio.TimeoutError:
101
101
print (' Timeout' )
102
102
```
103
103
104
- Register services and wait for connection: (Peripheral, Server)
104
+ #### Register services and wait for connection: (Peripheral, Server)
105
105
106
106
``` py
107
107
_ENV_SENSE_UUID = bluetooth.UUID(0x 181A )
@@ -126,30 +126,95 @@ while True:
126
126
print (" Connection from" , device)
127
127
```
128
128
129
- Update characteristic value: (Server)
129
+ #### Update characteristic value: (Server)
130
130
131
131
``` py
132
+ # Write the local value.
132
133
temp_char.write(b ' data' )
134
+ ```
135
+
136
+ ``` py
137
+ # Write the local value and notify/indicate subscribers.
138
+ temp_char.write(b ' data' , send_update = True )
139
+ ```
140
+
141
+ #### Send notifications: (Server)
133
142
134
- temp_char.notify(b ' optional data' )
143
+ ``` py
144
+ # Notify with the current value.
145
+ temp_char.notify(connection)
146
+ ```
135
147
136
- await temp_char.indicate(timeout_ms = 2000 )
148
+ ``` py
149
+ # Notify with a custom value.
150
+ temp_char.notify(connection, b ' optional data' )
137
151
```
138
152
139
- Query the value of a characteristic: (Client)
153
+ #### Send indications: (Server)
154
+
155
+ ``` py
156
+ # Indicate with current value.
157
+ await temp_char.indicate(connection, timeout_ms = 2000 )
158
+ ```
159
+
160
+ ``` py
161
+ # Indicate with custom value.
162
+ await temp_char.indicate(connection, b ' optional data' , timeout_ms = 2000 )
163
+ ```
164
+
165
+ This will raise ` GattError ` if the indication is not acknowledged.
166
+
167
+ #### Wait for a write from the client: (Server)
168
+
169
+ ``` py
170
+ # Normal characteristic, returns the connection that did the write.
171
+ connection = await char.written(timeout_ms = 2000 )
172
+ ```
173
+
174
+ ``` py
175
+ # Characteristic with capture enabled, also returns the value.
176
+ char = Characteristic(... , capture = True )
177
+ connection, data = await char.written(timeout_ms = 2000 )
178
+ ```
179
+
180
+ #### Query the value of a characteristic: (Client)
140
181
141
182
``` py
142
183
temp_service = await connection.service(_ENV_SENSE_UUID )
143
184
temp_char = await temp_service.characteristic(_ENV_SENSE_TEMP_UUID )
144
185
145
186
data = await temp_char.read(timeout_ms = 1000 )
187
+ ```
188
+
189
+ #### Wait for a notification/indication: (Client)
190
+
191
+ ``` py
192
+ # Notification
193
+ data = await temp_char.notified(timeout_ms = 1000 )
194
+ ```
146
195
196
+ ``` py
197
+ # Indication
198
+ data = await temp_char.indicated(timeout_ms = 1000 )
199
+ ```
200
+
201
+ #### Subscribe to a characteristic: (Client)
202
+
203
+ ``` py
204
+ # Subscribe for notification.
147
205
await temp_char.subscribe(notify = True )
148
206
while True :
149
207
data = await temp_char.notified()
150
208
```
151
209
152
- Open L2CAP channels: (Listener)
210
+ ``` py
211
+ # Subscribe for indication.
212
+ await temp_char.subscribe(indicate = True )
213
+ while True :
214
+ data = await temp_char.indicated()
215
+ ```
216
+
217
+ #### Open L2CAP channels: (Listener)
153
218
154
219
``` py
155
220
channel = await connection.l2cap_accept(_L2CAP_PSN , _L2CAP_MTU )
@@ -158,7 +223,7 @@ n = channel.recvinto(buf)
158
223
channel.send(b ' response' )
159
224
```
160
225
161
- Open L2CAP channels: (Initiator)
226
+ #### Open L2CAP channels: (Initiator)
162
227
163
228
``` py
164
229
channel = await connection.l2cap_connect(_L2CAP_PSN , _L2CAP_MTU )
0 commit comments