Struct esp32_nimble::BLEScan
source · pub struct BLEScan { /* private fields */ }
Expand description
Scan for ble devices.
§Examples
let ble_device = BLEDevice::take();
let ble_scan = BLEScan::new();
let name = "Device Name To Be Found";
let device = ble_scan
.start(ble_device, 10000, |device, data| {
if let Some(device_name) = data.name() {
if device_name == name {
return Some(*device);
}
}
None
})
.await
.unwrap();
Implementations§
source§impl BLEScan
impl BLEScan
pub fn new() -> Self
pub fn active_scan(&mut self, active: bool) -> &mut Self
pub fn filter_duplicates(&mut self, val: bool) -> &mut Self
sourcepub fn limited(&mut self, val: bool) -> &mut Self
pub fn limited(&mut self, val: bool) -> &mut Self
Set whether or not the BLE controller only report scan results from devices advertising in limited discovery mode, i.e. directed advertising.
sourcepub fn filter_policy(&mut self, val: ScanFilterPolicy) -> &mut Self
pub fn filter_policy(&mut self, val: ScanFilterPolicy) -> &mut Self
Sets the scan filter policy.
sourcepub async fn start<F, R>(
&mut self,
_ble_device: &BLEDevice,
duration_ms: i32,
callback: F,
) -> Result<Option<R>, BLEError>where
F: FnMut(&BLEAdvertisedDevice, BLEAdvertisedData<&[u8]>) -> Option<R>,
pub async fn start<F, R>(
&mut self,
_ble_device: &BLEDevice,
duration_ms: i32,
callback: F,
) -> Result<Option<R>, BLEError>where
F: FnMut(&BLEAdvertisedDevice, BLEAdvertisedData<&[u8]>) -> Option<R>,
The callback function must return Option type. If it returns None, the scan continues. If Some(r) is returned, the scan stops and the start function returns the return value of the callback.