GATT Client interface

class pybtle.gattc.gattc(cmd)

Generic Attribute Profile (GATT) Client class

code example

import gattc
import cmd
import gap
client = gattc.gattc(cmd.cmd())
client.connect(address, addr_type)
client.service_discovery()
connect(devId, addr, addrtype, sec_level)

Create a connection

Parameters:
  • devId (int) – Adapter index.
  • addr (str) – BLE address to connect (00:11:22:33:44:55).
  • addrtype (str) – “public” or “random”
  • sec_level (str) – security level from (“low”, “medium”, “high”)

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
}
get_db()

Retrieve GATT services, characteristics, descriptors found on GATT server

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
}
read(devId, chr, handle)

Perform a a GATT Read Characteristic or Descriptor procedure

Parameters:
  • devId (int) – adapter index.
  • chr (str) – characteristic uuid.
  • handle (int) – characteristic value handle.

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
    'value': "read value"
}
subscribe_notification(devId, chrc_uuid, notification_cb)

Subscribing to Notification.

Parameters:
  • devId (int) – adapter index.
  • chr (str) – characteristic uuid.
  • notification_cb (func) – Notification callback.

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
}
unsubscribe_notification(devId, chrc_uuid)

Unsubscribing to Notification.

Parameters:
  • devId (int) – adapter index.
  • chr (str) – characteristic uuid.

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
}
write_cmd(devId, chr, handle, value)

Perform a write without response

Parameters:
  • devId (int) – adapter index.
  • chr (str) – characteristic uuid.
  • handle (int) – characteristic value handle.
  • value (str) – data to write.

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
}
write_req(devId, chr, handle, value)

Perform a write with response

Parameters:
  • devId (int) – adapter index.
  • chr (str) – characteristic uuid.
  • handle (int) – characteristic value handle.
  • value (str) – data to write.

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
}