blatann.examples.peripheral_async module

This example exhibits some of the functionality of a peripheral BLE device, such as reading, writing, and notifying characteristics, utilizing asyncio to handle each characteristic in its own coroutine operating on the main thread. This async example is functionally equivalent to the other peripheral example, though some logging callbacks and database discovery on the central is not performed.

This example can be used with one of the central examples running on a separate nordic device, or can be run with the nRF Connect app to explore the contents of the GATT database.

blatann.examples.peripheral_async.on_connect(peer, event_args)

Event callback for when a central device connects to us

Parameters:
  • peer (Client) – The peer that connected to us

  • event_args (None) – None

blatann.examples.peripheral_async.on_disconnect(peer, event_args)

Event callback for when the client disconnects from us (or when we disconnect from the client)

Parameters:
async blatann.examples.peripheral_async.handle_hex_conversion_characteristic(peer, characteristic)

Coroutine that handles writes on the hex conversion characteristic. This coroutine does not exit until cancelled by the main task.

Parameters:
  • peer (Client) – The client object to wait on connections

  • characteristic (GattsCharacteristic) – The hex conversion characteristic

blatann.examples.peripheral_async.on_time_char_read(characteristic, event_args)

Event callback for when the client reads our time characteristic. Gets the current time and updates the characteristic. This demonstrates “lazy evaluation” of characteristics–instead of having to constantly update this characteristic, it is only updated when read/observed by an outside actor.

Note: using an async event queue for reads is less useful because setting the characteristic’s new value must occur before the event handling is finished and the read response is provided to the peer. Since the event queue delegates the event to the main context, the read response is sent before the event can be handled.

Parameters:
async blatann.examples.peripheral_async.handle_counting_characteristic(peer, characteristic)

Coroutine that dispatches notifications on the counting characteristic. This coroutine does not exit until cancelled by the main task.

Parameters:
  • peer (Client) – The client object to wait on connections

  • characteristic (GattsCharacteristic) – The hex conversion characteristic

blatann.examples.peripheral_async.on_passkey_display(peer, event_args)

Event callback that is called when a passkey is required to be displayed to a user for the pairing process.

Parameters:
blatann.examples.peripheral_async.on_passkey_entry(peer, passkey_event_args)

Callback for when the user is requested to enter a passkey to resume the pairing process. Requests the user to enter the passkey and resolves the event with the passkey entered

Parameters:
blatann.examples.peripheral_async.main(serial_port)