You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i'm currently running a debian 11 install with bluez 5.55 on it (the default package version from debian repo) and want to implement a small geofencing application.
Currently i'm stuck in bluer not getting any pairing requests from bluez.
This is the rust code:
use bluer::{id, agent::{Agent,RequestAuthorization,ReqResult,RequestConfirmation,AuthorizeService,DisplayPinCode,DisplayPasskey},Uuid,UuidExt};use core::time;use std::{thread, str::FromStr, fmt};use log::{info};#[derive(Clone,Copy)]structUuidOrShort(pubUuid);implFromStrforUuidOrShort{typeErr = String;fnfrom_str(s:&str) -> std::result::Result<Self,Self::Err>{match s.parse::<Uuid>(){Ok(uuid) => Ok(Self(uuid)),Err(_) => match u16::from_str_radix(s,16){Ok(short) => Ok(Self(Uuid::from_u16(short))),Err(_) => Err(s.to_string()),},}}}implFrom<UuidOrShort>forUuid{fnfrom(u:UuidOrShort) -> Self{
u.0}}implFrom<Uuid>forUuidOrShort{fnfrom(u:Uuid) -> Self{Self(u)}}impl fmt::DisplayforUuidOrShort{fnfmt(&self,f:&mut fmt::Formatter) -> fmt::Result{ifletSome(s) = self.0.as_u16(){write!(f, "{:04x}", s)}else{write!(f, "{}", self.0)}}}asyncfnrequest_authorization(req:RequestAuthorization) -> ReqResult<()>{info!("Is device {} on {} allowed to pair? (y/n)", &req.device, &req.adapter);Ok(())}asyncfnrequest_confirmation(req:RequestConfirmation) -> ReqResult<()>{info!("Is device {} on {} allowed to pair? (y/n)", &req.device, &req.adapter);Ok(())}asyncfnauthorize_service(req:AuthorizeService) -> ReqResult<()>{let service_id = match id::Service::try_from(req.service){Ok(name) => format!("{} ({})", name, UuidOrShort(req.service)),Err(_) => format!("{}", UuidOrShort(req.service)),};info!("Is device {} on {} allowed to use service {}? (y/n)", &req.device, &req.adapter, service_id);Ok(())}asyncfndisplay_pin_code(req:DisplayPinCode) -> ReqResult<()>{info!("PIN code for device {} on {} is \"{}\"", &req.device, &req.adapter, req.pincode);Ok(())}asyncfndisplay_passkey(req:DisplayPasskey) -> ReqResult<()>{info!("Passkey for device {} on {} is \"{:06}\"", &req.device, &req.adapter, req.passkey);Ok(())}#[tokio::main(flavor = "current_thread")]asyncfnmain() -> bluer::Result<()>{
env_logger::init();let session = bluer::Session::new().await?;let adapter = session.default_adapter().await?;info!("Free pairing devices for {}", adapter.name());
adapter.set_powered(true).await?;let agent = Agent{request_default:true,display_pin_code:Some(Box::new(|req| Box::pin(display_pin_code(req)))),display_passkey:Some(Box::new(|req| Box::pin(display_passkey(req)))),request_confirmation:Some(Box::new(move |req| {Box::pin(request_confirmation(req))})),request_authorization:Some(Box::new(move |req| {Box::pin(request_authorization(req))})),authorize_service:Some(Box::new(|req| Box::pin(authorize_service(req)))),
..Default::default()};let _agent_handle = session.register_agent(agent).await?;
adapter.set_pairable_timeout(0).await?;
adapter.set_pairable(true).await?;
adapter.set_discoverable_timeout(0).await?;
adapter.set_discoverable(true).await?;
thread::sleep(time::Duration::from_secs(600));Ok(())}
BlueZ returns a src/agent.c:simple_agent_reply() Timed out waiting for reply from agent when not in debug mode.
BlueR trace logs:
[2022-04-08T22:44:43Z TRACE bluer::session] Connected to D-Bus with unique name :1.1911
[2022-04-08T22:44:43Z TRACE mio::poll] registering event source with poller: token=Token(1), interests=READABLE
[2022-04-08T22:44:43Z TRACE bluer::session] Starting event loop for :1.1911
[2022-04-08T22:44:43Z INFO ble_fencer] Free pairing devices for hci0
[2022-04-08T22:44:43Z TRACE bluer::adapter] /org/bluez/hci0: org.bluez.Adapter1.Powered := true
[2022-04-08T22:44:43Z TRACE bluer::agent] Publishing agent at /org/bluez/bluer/agent/af0e3da48d3b4568a49ccc8b8a9bb289 with capability DisplayYesNo
[2022-04-08T22:44:43Z TRACE bluer::agent] Registering agent at /org/bluez/bluer/agent/af0e3da48d3b4568a49ccc8b8a9bb289
[2022-04-08T22:44:43Z TRACE bluer::agent] Requesting default agent for /org/bluez/bluer/agent/af0e3da48d3b4568a49ccc8b8a9bb289
[2022-04-08T22:44:43Z TRACE bluer::adapter] /org/bluez/hci0: org.bluez.Adapter1.PairableTimeout := 0
[2022-04-08T22:44:43Z TRACE bluer::adapter] /org/bluez/hci0: org.bluez.Adapter1.Pairable := true
[2022-04-08T22:44:43Z TRACE bluer::adapter] /org/bluez/hci0: org.bluez.Adapter1.DiscoverableTimeout := 0
[2022-04-08T22:44:43Z TRACE bluer::adapter] /org/bluez/hci0: org.bluez.Adapter1.Discoverable := true
Just to let everyone know. Sleeping on the main thread is a stupid idea since nothing will get any messages anymore. Using tokio sleep solved the problem for me.
surban
changed the title
Added Agent doesn't recieve pairing requests in any form
Sleeping on main thread prevents dispatching of events
Apr 9, 2022
bluez
locked and limited conversation to collaborators
Apr 9, 2022
Hi,
i'm currently running a debian 11 install with bluez 5.55 on it (the default package version from debian repo) and want to implement a small geofencing application.
Currently i'm stuck in bluer not getting any pairing requests from bluez.
This is the rust code:
BlueZ returns a
src/agent.c:simple_agent_reply() Timed out waiting for reply from agent
when not in debug mode.BlueR trace logs:
BlueZ journalctl with debug on:
Is this because i don't run blueZ 5.60? If so would it be possible, maybe with a PR, to get compability with the default debian version?
Thanks :)
The text was updated successfully, but these errors were encountered: