Struct esp32_nimble::BLEServer
source · pub struct BLEServer { /* private fields */ }
Implementations§
source§impl BLEServer
impl BLEServer
pub fn on_connect( &mut self, callback: impl FnMut(&mut Self, &BLEConnDesc) + Send + Sync + 'static, ) -> &mut Self
sourcepub fn on_disconnect(
&mut self,
callback: impl FnMut(&BLEConnDesc, Result<(), BLEError>) + Send + Sync + 'static,
) -> &mut Self
pub fn on_disconnect( &mut self, callback: impl FnMut(&BLEConnDesc, Result<(), BLEError>) + Send + Sync + 'static, ) -> &mut Self
Handle a client disconnection.
- callback first parameter: A reference to a
esp_idf_sys::ble_gap_conn_desc
instance with information about the peer connection parameters. - callback second parameter: The reason code for the disconnection.
sourcepub fn on_passkey_request(
&mut self,
callback: impl Fn() -> u32 + Send + Sync + 'static,
) -> &mut Self
pub fn on_passkey_request( &mut self, callback: impl Fn() -> u32 + Send + Sync + 'static, ) -> &mut Self
Set a callback fn for generating a passkey if required by the connection
- The passkey will always be exactly 6 digits. Setting the passkey to 1234 will require the user to provide ‘001234’
- a static passkey can also be set by
crate::BLESecurity::set_passkey
pub fn on_confirm_pin( &mut self, callback: impl Fn(u32) -> bool + Send + Sync + 'static, ) -> &mut Self
sourcepub fn on_authentication_complete(
&mut self,
callback: impl Fn(&BLEConnDesc, Result<(), BLEError>) + Send + Sync + 'static,
) -> &mut Self
pub fn on_authentication_complete( &mut self, callback: impl Fn(&BLEConnDesc, Result<(), BLEError>) + Send + Sync + 'static, ) -> &mut Self
The callback function is called when the pairing procedure is complete.
- callback first parameter: A reference to a
BLEConnDesc
instance. - callback second parameter: Indicates the result of the encryption state change attempt; o 0: the encrypted state was successfully updated; o BLE host error code: the encryption state change attempt failed for the specified reason.
pub fn start(&mut self) -> Result<(), BLEError>
sourcepub fn disconnect(&mut self, conn_id: u16) -> Result<(), BLEError>
pub fn disconnect(&mut self, conn_id: u16) -> Result<(), BLEError>
Disconnect the specified client.
sourcepub fn disconnect_with_reason(
&mut self,
conn_id: u16,
reason: u8,
) -> Result<(), BLEError>
pub fn disconnect_with_reason( &mut self, conn_id: u16, reason: u8, ) -> Result<(), BLEError>
Disconnect the specified client with optional reason.
sourcepub fn ble_gatts_show_local(&self)
pub fn ble_gatts_show_local(&self)
Prints dump of local GATT database. This is useful to log local state of database in human readable form.
pub fn connected_count(&self) -> usize
pub fn connections(&self) -> impl Iterator<Item = BLEConnDesc> + '_
pub fn create_service(&mut self, uuid: BleUuid) -> Arc<Mutex<BLEService>>
sourcepub async fn get_service(
&self,
uuid: BleUuid,
) -> Option<&Arc<Mutex<BLEService>>>
pub async fn get_service( &self, uuid: BleUuid, ) -> Option<&Arc<Mutex<BLEService>>>
Get the service object for the UUID.
sourcepub fn advertise_on_disconnect(&mut self, value: bool) -> &mut Self
pub fn advertise_on_disconnect(&mut self, value: bool) -> &mut Self
Set the server to automatically start advertising when a client disconnects.
sourcepub fn update_conn_params(
&mut self,
conn_handle: u16,
min_interval: u16,
max_interval: u16,
latency: u16,
timeout: u16,
) -> Result<(), BLEError>
pub fn update_conn_params( &mut self, conn_handle: u16, min_interval: u16, max_interval: u16, latency: u16, timeout: u16, ) -> Result<(), BLEError>
Request an Update the connection parameters: Can only be used after a connection has been established.
conn_handle
: The connection handle of the peer to send the request to.min_interval
: The minimum connection interval in 1.25ms units.max_interval
: The maximum connection interval in 1.25ms units.latency
: The number of packets allowed to skip (extends max interval).timeout
: The timeout time in 10ms units before disconnecting.