Sideband/libs/able/tests/notebooks/test_scan_settings.md
2025-10-29 12:54:59 +01:00

1.7 KiB

jupyter
jupytext kernelspec
formats text_representation
ipynb,md
extension format_name format_version jupytext_version
.md markdown 1.3 1.11.2
display_name language name
Python 3 python python3

Setup

%run init.ipynb
%%there
class BLE(BluetoothDispatcher):

    def on_scan_started(self, success):
        results.started = success
        
    def on_scan_completed(self):
        results.completed = 1
        
    def on_device(self, device, rssi, advertisement):
        results.devices.append(device)

def get_advertisemnt_count():
    return len([dev for dev in results.devices if dev.getName() == "KivyBLETest"])        

ble = BLE()

Run SCAN_MODE_LOW_POWER

%%there
results =  Results()
ble.start_scan(
    settings=ScanSettingsBuilder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
)
sleep(20)
%%there
ble.stop_scan()
sleep(2)
%%there
low_power_advertisement_count = get_advertisemnt_count()
print(low_power_advertisement_count > 0)

Run SCAN_MODE_LOW_LATENCY

%%there
results =  Results()

ble.start_scan(
    settings=ScanSettingsBuilder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
)
sleep(20)
%%there
ble.stop_scan()
sleep(2)
%%there
low_latency_advertisement_count = get_advertisemnt_count()
print(low_latency_advertisement_count > 0)

Check that received advertisement count is greater with SCAN_MODE_LOW_LATENCY

%%there
print(low_latency_advertisement_count - low_power_advertisement_count > 2)