Scans for nearby devices. This method blocks while the scan is ongoing.
Only one scan can run at a time.
If active is true, then we request a scan response from discovered devices. Users may need to merge the advertisement data from the scan response with the advertisement data from the discovery event. Use RemoteScannedDevice.is-scan-response to distinguish between the two. Connections cannot be established while a scan is ongoing.
Stops the scan after the given duration.
The interval is the time between the start of two consecutive scan windows. It is given in units of 0.625 ms. If it is 0, the default value of the system is used.
The window is the time the scanner is active during a scan window. It is given in units of 0.625 ms. If it is 0, the default value of the system is used. The window must be less than or equal to the interval.
If limited-only is true, only limited discoverable devices are reported. Devices declare during advertising whether they are limited (advertising for a limited duration) or general (continuously broadcasting). This flag filters out general devices.
Merging advertisements
When active is true, then there are two calls to the block for each device. The first call is for the discovery event, and the second call is for the scan response event. It is up to the user to merge the advertisement data from the two calls.
A simple way to merge advertisement data is to concatenate the DataBlock entries of the advertisements.
discovered-blocks := {:}
central.scan --duration=(Duration --s=2) --active: | device/RemoteScannedDevice |
blocks := discovered-blocks.get device.identifier --init=: {}
blocks.add-all device.data.data-blocks
// Construct a map from identifier to the discovered advertisements.
discovered-advertisements := discovered-blocks.map: | _ blocks |
Advertisement blocks.to-list --no-check-size