Device Scanning
Bluetooth Low Energy scanning is provided by a dedicated connector, whad.ble.connector.Scanner
,
that drives a BLE-enable WHAD device to detect any available BLE device. This connector relies
on an internal database implemented in whad.ble.scanning.AdvertisingDevicesDB
that keeps
track of every detected device.
Bluetooth Low Energy Scanner connector
- class whad.ble.connector.Scanner(device)[source]
BLE Observer interface for compatible WHAD device.
- discover_devices(minimal_rssi=None, filter_address=None, timeout: float = None) Iterator[AdvertisingDevice] [source]
Parse incoming advertisements and yield discovered devices.
- Parameters:
minimal_rssi (float, optional) – Minimal RSSI level
filter_address (
whad.ble.bdaddr.BDAddress
, optional) – BD address of a device to discovertimeout (float, optional) – Timeout in seconds
BLE device tracking database
Devices are tracked by the BLE scanner connector by a dedicated database, each
device is then wrapped into a whad.ble.scanning.AdvertisingDevice
instance
that holds all the interesting information.
- class whad.ble.scanning.AdvertisingDevice(rssi, address_type, bd_address, adv_data, rsp_data=None, undirected=True, connectable=True)[source]
Store information about a device:
Received Signal Strength Indicator (RSSI)
Address type (public or random)
Advertising data
Scan response data
Type of advertising PDU
Connectable information
- property ad_records: AdvDataFieldList
Combined advertising and scan response records.
- property address: str
Device BD address.
- property address_type: int
Device address type.
- property adv_records: bytes
Advertising records.
- property connectable: bool
Connectable status.
- property got_scan_rsp: bool
Received a scan response from device.
- property last_seen: float
Device last seen timestamp.
- property name: str
Device complete or short name.
- property rssi: float
Device RSSI.
- property scan_rsp_records: bytes
Scan response records.
- property scanned: bool
Device scanned status
- set_scan_rsp(scan_rsp)[source]
Update device advertisement data.
- Parameters:
scan_rsp (bytes) – Raw scan response.
- property timestamp: float
Device discovery timestamp.
- class whad.ble.scanning.AdvertisingDevicesDB[source]
Bluetooth Low Energy devices database.
This class stores information about discovered devices.
- find_device(address) AdvertisingDevice [source]
Find a device based on its BD address.
- Parameters:
address (str) – Device BD address
- Returns:
Device if found, None otherwise.
- Return type:
- on_device_found(rssi, adv_packet, filter_addr=None)[source]
Device advertising packet or scan response received.
Parse the incoming packet and handle device appropriately.
- Parameters:
rssi (float) – Received Signal Strength Indicator
adv_packet (
scapy.packet.Packet
) – Advertising packetfilter_addr (str) – BD address to filter
- register_device(device)[source]
Register or update a device.
- Parameters:
device (
whad.ble.scanning.AdvertisingDevice
) – Device to register.