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
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
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
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
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
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
blatann.examples.peripheral.on_client_pairing_complete(peer, event_args)

Event callback for when the pairing process completes with the client

Parameters
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
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
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)