cmd interface

class pybtle.cmd.cmd

Responsible for (de)serializing command and notify upper layer

conn_param(adapter, addr, min, max, latency, timeout)

Sending set connection parameter command

Parameters:
  • adapter (int) – Adapter index
  • addr (str) – BLE address
  • min (int) – Minimum connection interval
  • max (int) – Maximum connection interval
  • latency (int) – latency
  • timeout (int) – Supervision timeout

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
}
connect(adapter, addr, addrtype, sec_level, service_discovery_cb)

Sending create connection command

Parameters:
  • adapter (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”)
  • discovery_cb (callback) –

Returns:

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

nothing to do as status has already been checked

parse_write_characteristic_rsp(data, data_len)

nothing to do as status has already been checked

power_off(adapter)

Sendind powering OFF command

Parameters:adapter (int) – Adapter index

Returns:

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

Sending powering ON command

Parameters:adapter (int) – Adapter index

Returns:

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

Sending reading controller information command

Parameters:adapter (int) – Adapter index

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
    'version': "hex"
    'manufacturer': "hex"
    'supported_settings': "hex"
    'current_settings': "hex"
    'dev_class': "hex"
    'name': "str"
}
scan_start(adapter, scan_delegate)

Sending start BLE scan command

Parameters:adapter (int) – Adapter index

Returns:

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

Sending stop BLE scan command

Parameters:adapter (int) – Adapter index

Returns:

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

Sending set Advertising local Name command

Parameters:
  • adapter (int) – Adapter index
  • name (str) – Advertising local Name

Returns:

{
    'result': ("ok", "error"),
    'reason': "failure reason"
}
subscribe(adapter, value_handle, value, notification_cb)

Sending Notification / Indication subscription command

Parameters:
  • adapter (int) – adapter index.
  • value_handle (int) – characteristic value handle
  • value (int) – 1 for Notification; 2 for Indication
  • notification_cb (func) – Notification callback.

Returns:

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

Sending stop BLE scan command

Parameters:
  • adapter (int) – Adapter index
  • cccd_id (int) – Subscription ID

Returns:

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