Hi, I am a beginner in rust, and I am trying to catch advertisement data of my BLE thermometer. In order to do that, I want to use bluez DBUS API.
I use the dbus-rs crate to achieve dbus communication.
I have manage to subscribe to the dbus and start/stop scan around but I need to subscribe to new object enumeration. For this purpose I use the match_start function of the Proxy struct but I can't understand what I am supposed to pass as third parameter of the method. I would expect to pass something like a callback but instead the parameter's type is <T as MatchingReceiver>::F . I have read the rust documentation about associated types and generics but I am unable to understand anyway.
Well you're almost there. The thing is, <T as MatchingReceiver>::Fis the type of the callback. Looking at the trait MatchingReceiver, you will see that it indeed has an associated type F.
As for how you obtain an instance of that type, that depends on your instance of type T, which must implement the MatchingReceiver trait. It has a list of implementing types, have a look at them.
But even if I have successfully chosen one, I am not sure about my logic:
I have chosen a closure which match the concrete type of the "connection" field (which is generic) inside the calling object (adapter_proxy).
I currently did the same thing, reading advertisement data of BLE-devices.
From my experince I recommend the bluez crate to you. The provided example worked for me out of the box as the DeviceFound event directly gives access to the EIR-data which includes the manufacturer specific data (ID=0xFF) which probably holds your temperature.
The crate is a little bit low-level (for now) but already has sufficient async/.await support. And as said it provides everything you need if you are not reluctant to implement some parsing logic yourself.
Yeah I have ever tried this using another crate, rumble (which is not maintained anymore and superdeded by btleplug. Unfortunately, the manufacturer data field is empty when I discover my device, that's why I decided to check the whole advertisement data payload using bluez api.