Level 10¶
Broadcaster¶
The level 10 file for creating beacons This requires BlueZ to have the experimental flag set
-
class
bluezero.broadcaster.
Beacon
(adapter_addr=None)¶ Create a non-connectable Bluetooth instance advertising information
-
add_manufacturer_data
(manufacturer, data)¶ Add manufacturer information to be used in beacon message :param manufacturer: Use numbers from Bluetooth SIG https://www.bluetooth.com/specifications/assigned-numbers/16-bit-UUIDs-for-Members :param data: Data to be sent (Limit of ??)
-
add_service_data
(service, data)¶ Add service and service data to be used in beacon message :param service: Valid service UUID :param data: Data to be sent (Limit of ??)
-
include_tx_power
(show_power=None)¶ Use to include TX power in advertisement. This is different to the TX power in specific beacon format (e.g. Eddystone) :param show_power: boolean value :return:
-
start_beacon
()¶ Start beacon advertising
-
Central¶
Classes that represent the GATT features of a remote device.
-
class
bluezero.central.
Central
(device_addr, adapter_addr=None)¶ Create a BLE instance taking the Central role.
-
add_characteristic
(srv_uuid, chrc_uuid)¶ Specify a characteristic of interest on the remote device by using the GATT Service UUID and Characteristic UUID :param srv_uuid: 128 bit UUID :param chrc_uuid: 128 bit UUID :return:
-
static
available
(adapter_address=None)¶ Generator for getting a list of devices
-
connect
(profile=None, timeout=35)¶ Initiate a connection to the remote device and load GATT database once resolved
Parameters: - profile – (optional) profile to use for the connection.
- timeout – (optional) seconds to wait for connection.
-
connected
¶ Indicate whether the remote device is currently connected.
-
disconnect
()¶ Disconnect from the remote device.
-
load_gatt
()¶ Once the remote device has been connected to and the GATT database has been resolved then it needs to be loaded. :return:
-
quit
()¶ Stop event loop
-
run
()¶ Start event loop
-
services_available
¶ Get a list of Service UUIDs available on this device
-
services_resolved
¶ Return a list of UIDDs that are available on the device
-
Observer¶
Code for create a Bluetooth Low Energy Observer (beacon scanner) application
-
class
bluezero.observer.
AltBeacon
(UUID, major, minor, tx_pwr, rssi)¶ -
UUID
¶ Alias for field number 0
-
major
¶ Alias for field number 1
-
minor
¶ Alias for field number 2
-
rssi
¶ Alias for field number 4
-
tx_pwr
¶ Alias for field number 3
-
-
class
bluezero.observer.
EddyUID
(namespace, instance, tx_pwr, rssi)¶ -
instance
¶ Alias for field number 1
-
namespace
¶ Alias for field number 0
-
rssi
¶ Alias for field number 3
-
tx_pwr
¶ Alias for field number 2
-
-
class
bluezero.observer.
EddyURL
(url, tx_pwr, rssi)¶ -
rssi
¶ Alias for field number 2
-
tx_pwr
¶ Alias for field number 1
-
url
¶ Alias for field number 0
-
-
class
bluezero.observer.
Scanner
¶ For scanning of Bluetooth Low Energy (BLE) beacons
-
static
ble_16bit_match
(uuid_16, srv_data)¶ Utility method to test 16 bit UUID against Bluetooth SIG 128 bit UUID used in service data :param uuid_16: 16 Bit UUID value :param srv_data: :return:
-
classmethod
clean_beacons
()¶ Remove beacons from BlueZ’s devices list so every advert from a beacon is reported
-
classmethod
on_device_found
(bz_device_obj)¶ Callback to look at BLE advertisement to see if it is a recognised beacon and if it is, then call the relevant processing function :param bz_device_obj: Bluezero device object of discovered device
-
classmethod
process_eddystone
(data, rssi)¶ Extract Eddystone data from advertisement service data :param data: Bytes from Service Data in advertisement :param rssi: Received Signal Strength value
-
classmethod
process_ibeacon
(data, rssi, beacon_type='iBeacon')¶ Extract iBeacon or AltBeacon data from Manufacturer Data in an advertisement :param data: Bytes from manufacturer data :param rssi: Received Signal Strength value :param beacon_type: iBeacon or AltBeacon
-
classmethod
start_beacon_scan
(on_eddystone_url=None, on_eddystone_uid=None, on_ibeacon=None, on_altbeacon=None)¶ Start scan for beacons. Provided callback will be called if matching beacon type is found. All callbacks take one argument which is a named tuple with the fields relevant for that format.
Eddystone URL = [‘url’, ‘tx_pwr’, ‘rssi’] Eddystone UID = [‘namespace’, ‘instance’, ‘tx_pwr’, ‘rssi’] iBeacon = [‘UUID’, ‘major’, ‘minor’, ‘tx_pwr’, ‘rssi’] AltBeacon = [‘UUID’, ‘major’, ‘minor’, ‘tx_pwr’, ‘rssi’]Parameters: - on_eddystone_url – Callback for Eddystone URL format
- on_eddystone_uid – Callback for Eddystone UID format
- on_ibeacon – Callback for iBeacon format
- on_altbeacon – Callback for AltBeacon format
-
classmethod
start_event_loop
()¶ Start the event loop
-
classmethod
stop_scan
()¶ Stop scanning for beacons
-
static
-
class
bluezero.observer.
iBeacon
(UUID, major, minor, tx_pwr, rssi)¶ -
UUID
¶ Alias for field number 0
-
major
¶ Alias for field number 1
-
minor
¶ Alias for field number 2
-
rssi
¶ Alias for field number 4
-
tx_pwr
¶ Alias for field number 3
-
-
bluezero.observer.
scan_eddystone
(on_data=None)¶ Provide a callback for ‘on_data’. The callback will be run whenever an Eddystone URL packet is detected.
Parameters: on_data – A function to be called on Eddystone packet Returns: None
Peripheral¶
Classes required to create a Bluetooth Peripheral.
Current classes include:
- Application – Root class
- Service – Bluetooth Service
- Characteristic – Bluetooth Characteristic
- Descriptor – Bluetooth Descriptor
- Advertisement – Bluetooth Advertisement
This requires BlueZ to have the experimental flag to be enabled
-
bluezero.peripheral.
register_ad_cb
()¶ Advertisement registration callback.
-
bluezero.peripheral.
register_ad_error_cb
(error)¶ Advertisement registration error callback.
-
bluezero.peripheral.
register_service_cb
()¶ Service registration callback.
-
bluezero.peripheral.
register_service_error_cb
(error)¶ Service registration error callback.