blatann.examples.peripheral module¶
This example exhibits some of the functionality of a peripheral BLE device, such as reading, writing and notifying characteristics.
This peripheral 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 service
- blatann.examples.peripheral.on_connect(peer, event_args)¶
Event callback for when a central device connects to us
- Parameters
peer (blatann.peer.Client) – The peer that connected to us
event_args – None
- blatann.examples.peripheral.on_disconnect(peer, event_args)¶
Event callback for when the client disconnects from us (or when we disconnect from the client)
- Parameters
peer (blatann.peer.Client) – The peer that disconnected
event_args (blatann.event_args.DisconnectionEventArgs) – The event args
- blatann.examples.peripheral.on_hex_conversion_characteristic_write(characteristic, event_args)¶
Event callback for when the client writes to the hex conversion characteristic. This takes the data written, converts it to the hex representation, and updates the characteristic with this new value. If the client is subscribed to the characteristic, the client will be notified.
- Parameters
characteristic (blatann.gatt.gatts.GattsCharacteristic) – The hex conversion characteristic
event_args (blatann.event_args.WriteEventArgs) – the event arguments
- blatann.examples.peripheral.on_gatts_subscription_state_changed(characteristic, event_args)¶
Event callback for when a client subscribes or unsubscribes from a characteristic. This is the equivalent to when a client writes to a CCCD descriptor on a characteristic.
- blatann.examples.peripheral.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.
- Parameters
characteristic (blatann.gatt.gatts.GattsCharacteristic) – the time characteristic
event_args – None
- blatann.examples.peripheral.on_discovery_complete(peer, event_args)¶
Callback for when the service discovery completes on the client. This will look for the client’s Device name characteristic (part of the Generic Access Service) and read the value
- Parameters
peer (blatann.peer.Client) – The peer the discovery completed on
event_args (blatann.event_args.DatabaseDiscoveryCompleteEventArgs) – The event arguments (unused)
- blatann.examples.peripheral.on_security_level_changed(peer, event_args)¶
Called when the security level changes, i.e. a bonded device connects and enables encryption or pairing has finished. If security has been enabled (i.e. bonded) and the peer’s services have yet to be discovered, discover now.
This code demonstrates that even in a peripheral connection role, the peripheral can still discover the database on the client, if the client has a database.
- Parameters
peer (blatann.peer.Client) – The peer that security was changed to
event_args (blatann.event_args.SecurityLevelChangedEventArgs) – the event arguments
- blatann.examples.peripheral.on_client_pairing_complete(peer, event_args)¶
Event callback for when the pairing process completes with the client
- Parameters
peer (blatann.peer.Client) – the peer that completed pairing
event_args (blatann.event_args.PairingCompleteEventArgs) – the event arguments
- blatann.examples.peripheral.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
peer (blatann.peer.Client) – The peer the passkey is for
event_args (blatann.event_args.PasskeyDisplayEventArgs) – The event args
- blatann.examples.peripheral.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
peer – the peer the passkey is for
passkey_event_args (blatann.event_args.PasskeyEntryEventArgs) –
- class blatann.examples.peripheral.CountingCharacteristicThread(characteristic)¶
Bases:
object
Thread which updates the counting characteristic and notifies the client each time its updated. This also demonstrates the notification queuing functionality–if a notification/indication is already in progress, future notifications will be queued and sent out when the previous ones complete.
- join()¶
Used to stop and join the thread
- run()¶
- blatann.examples.peripheral.on_conn_params_updated(peer, event_args)¶
- blatann.examples.peripheral.main(serial_port)¶