Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 2b4dc1c

Browse files
committed
esp32/network_bluetooth.c: All properties now functions
esp32/bluetooth_docs.md: All properties now functions
1 parent fc166f7 commit 2b4dc1c

File tree

2 files changed

+233
-269
lines changed

2 files changed

+233
-269
lines changed

esp32/bluetooth_docs.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ bluetooth.ble_settings(int_min = 1280, int_max = 1280,
107107

108108
`bluetooth.Service(uuid, is_primary = True)` GATTS - create a new GATTSService object. `uuid` is either an integer or a `bytes(16)`. UUIDs are globally unique with in GATTS. If you attempt to create a service with a UUID that is the same as an existing (but not closed) service, you will receive the same service object, and no new service will be created.
109109

110-
`bluetooth.services` GATTS - returns the existing GATTS services.
110+
`bluetooth.services()` GATTS - returns the existing GATTS services.
111111

112112
`bluetooth.callback(<callback>, <callback_data>)` used to set the callback function for bluetooth-object-level callbacks. `<callback>` can be set to None. If `<callback_data>` is not specified, it will be set to None. Always returns a 2-tuple of the present `<callback>` and `<callback_data>`. If called with no parameters, the values remain unchanged. `<callback>` will be called with 4 parameters:
113113

@@ -147,7 +147,7 @@ bluetooth.ble_settings(int_min = 1280, int_max = 1280,
147147

148148
`bluetooth.scan_stop()` GATTC - terminate scanning early. If called before the scan timeout, you will _not_ receive a `bluetooth.SCAN_CMPL` event.
149149

150-
`bluetooth.is_scanning` GATTC - returns `True` if the scan is still active
150+
`bluetooth.is_scanning()` GATTC - returns `True` if the scan is still active
151151

152152
## GAP
153153

@@ -190,11 +190,11 @@ GATTSService objects are created by calling the `bluetooth.Service()` constructo
190190
* `bluetooth.PROP_AUTH`
191191
* `bluetooth.PROP_EXT_PROP`
192192

193-
`service.chars` Get the characteristics attached to this service.
193+
`service.chars()` Get the characteristics attached to this service.
194194

195-
`service.is_primary` Get the value of the srvice `primary` flag.
195+
`service.is_primary()` Get the value of the srvice `primary` flag.
196196

197-
`char.uuid` Get the service UUID.
197+
`char.uuid()` Get the service UUID.
198198

199199
`service.start()` Start the service; it will be visible to any connecting GATTC.
200200

@@ -223,23 +223,23 @@ In the absence of a callback, then the characteristic value is return for a read
223223

224224
`char.notify(<value>)` Send a notify value. `<value>` is `string`, `bytearray`, `bytes` or `None`.
225225

226-
`char.uuid` Get the characteristic UUID.
226+
`char.uuid()` Get the characteristic UUID.
227227

228-
`char.value` Get or set the characteristic value.
228+
`char.value([value])` Get or set the characteristic value.
229229

230-
`char.service` Get the parent service.
230+
`char.service()` Get the parent service.
231231

232232
`char.Descr(uuid, value = None, perm = bluetooth.PERM_READ | bluetooth.PERM_WRITE)` Create a new descriptor for a characteristic.
233233

234234
`char.descrs` Get the descriptors associated with the characteristic
235235

236236
### GATTSDescr objects
237237

238-
`descr.uuid` Get the descriptor UUID.
238+
`descr.uuid()` Get the descriptor UUID.
239239

240-
`descr.value` Get or set the value.
240+
`descr.value([value])` Get or set the value.
241241

242-
`descr.char` Get the parent characteristic.
242+
`descr.char()` Get the parent characteristic.
243243

244244
`descr.callback(<callback>, <callback_data>)` See `char.callback()`, above.
245245

@@ -251,19 +251,19 @@ Use `bluetooth.scan_start()`, to find GATTS devices. You'll need to set up a Bl
251251

252252
### GATTCConn objects
253253

254-
`conn.services` Returns the services associated with the connection. This is a list of [`GATTCService`](#gattcservice-objects) objects.
254+
`conn.services()` Returns the services associated with the connection. This is a list of [`GATTCService`](#gattcservice-objects) objects.
255255

256-
`conn.is_connected` Returns whether the connection is active or not.
256+
`conn.is_connected()` Returns whether the connection is active or not.
257257

258-
`conn.disconnect()` Disconnect
258+
`conn.disconnect()` Disconnect
259259

260260
### GATTCService objects
261261

262-
`service.is_primary` Returns a boolean indicating if the service is a primary service or not.
262+
`service.is_primary()` Returns a boolean indicating if the service is a primary service or not.
263263

264-
`service.uuid` Returns the service UUID
264+
`service.uuid()` Returns the service UUID
265265

266-
`service.chars` Returns a list of [`GATTCChar`](#gattcchar-objects) objects associated with this service
266+
`service.chars()` Returns a list of [`GATTCChar`](#gattcchar-objects) objects associated with this service
267267

268268
### GATTCChar objects
269269

@@ -277,23 +277,23 @@ When the callback is called, it will be called with 4 parameters:
277277
3. The value of the notify/indicate
278278
4. the `<callback_data>`
279279

280-
`char.descrs` Returns a list of [`GATTCDescr`](#gattcdescr-objects) associated with this characteristic.
280+
`char.descrs()` Returns a list of [`GATTCDescr`](#gattcdescr-objects) associated with this characteristic.
281281

282282
`char.read()` Read the characteristic value
283283

284284
`char.write(<value>)` Write a value to the characteristic. `<value>` can be `str`, `bytearray`, `bytes`, or `None`
285285

286286
### GATTCDescr objects
287287

288-
`GATTCChar` objects often have associated BLE desriptor objects. These can be obtained by accessing the `char.descrs` property of [`GATTCChar`](#gattcchar-objects) objects.
288+
`GATTCChar` objects often have associated BLE desriptor objects. These can be obtained by calling `char.descrs()` function of [`GATTCChar`](#gattcchar-objects) objects.
289289

290290
`descr.read()` Read from the descriptor.
291291

292292
`descr.write(<value>)` Write a value to the characteristic. `<value>` can be `str`, `bytearray`, `bytes`, or `None`
293293

294-
`descr.uuid` Get the descriptor UUID.
294+
`descr.uuid()` Get the descriptor UUID.
295295

296-
`descr.char` Get the [`GATTCChar`](#gattcchar-objects) the descriptor is attached to
296+
`descr.char()` Get the [`GATTCChar`](#gattcchar-objects) the descriptor is attached to
297297

298298
## Examples
299299

@@ -364,20 +364,24 @@ def hr(bda):
364364
''' Will connect to a BLE heartrate monitor, and enable HR notifications '''
365365

366366
conn = b.connect(bda)
367-
while not conn.is_connected:
367+
while not conn.is_connected():
368368
time.sleep(.1)
369369

370+
print ('Connected')
371+
370372
time.sleep(2) # Wait for services
371373

372-
service = ([s for s in conn.services if s.uuid[0:4] == b'\x00\x00\x18\x0d'] + [None])[0]
374+
service = ([s for s in conn.services() if s.uuid()[0:4] == b'\x00\x00\x18\x0d'] + [None])[0]
373375
if service:
374-
char = ([c for c in service.chars if c.uuid[0:4] == b'\x00\x00\x2a\x37'] + [None])[0]
376+
char = ([c for c in service.chars() if c.uuid()[0:4] == b'\x00\x00\x2a\x37'] + [None])[0]
375377
if char:
376-
descr = ([d for d in char.descrs if d.uuid[0:4] == b'\x00\x00\x29\x02'] + [None])[0]
378+
descr = ([d for d in char.descrs() if d.uuid()[0:4] == b'\x00\x00\x29\x02'] + [None])[0]
377379
if descr:
378380
char.callback(cb)
379381
descr.write(b'\x01\x00') # Turn on notify
380382

383+
return conn
384+
381385

382386
def gatts():
383387
s1 = b.Service(0xaabb)

0 commit comments

Comments
 (0)