-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for passive BLE scanning #27
Comments
This would probably be provided by the advertisement monitoring api which is indeed not yet implemented in BlueR. |
I'm working on this for a few days now, it's not working yet. It should, but bluez is not calling the callback functions. Maybe something with bluez? I compiled the latest version manually since monitoring API is something new. I forked bluer: The code is simple: callbacks:
code:
Now, a few things on bluer may complicate things further. BlueR changes some filters on discover_devices on the user's behalf, it doesn't allow duplicates, which could be a problem with beacons, and it does not allow us to choose a LE scan only. I think discover_devices is not necessary with passive scan, but if they work simultaneously, it could be a problem with beacons. I don't know. And sorry if my Rust code is not state of the art. I'm relatively new to Rust.. just trying to do my best here. regards, |
Oh, and I'm having a hard time with those or_patterns as well... but I will figure them out eventually. |
I also started a prototype a while ago, but forgot to post it here: lopsided98/bluer@master...adv-mon It works, but currently only supports one monitor at a time. The monitor root can only contain a single monitor right now because dbus-crossroads seems to only support sending added/removed signals for the root ObjectManager, so I can't tell BlueZ when a new monitor was added. I also found that adjusting any of the RSSI settings broke the monitor (I forget the exact details, but most of the time I would just get no notifications), and I was never able to get the DeviceLost callback to work reliably. These both appear to be BlueZ issues. Despite these issues, I was to get it working well for my application. To reliably get notifications when a device starts reappears after disappearing for a while, I have to re-register the monitor. My application code can be found here: https://github.com/lopsided98/WaterLevelMonitor/blob/54e8bc2219d0ef33d84bb9c4fb57ed287cb848a3/base_station/src/sensor.rs#L185 |
I managed to make it to work. At least receiving the Activate/Release callbacks. It was the object manager indeed. Once I implemented it on the monitor interface things started to work. I managed to implement object manager at the monitor path, so, in my version, you can have more than one monitor, as many as bluez allows. At least, in theory, I will make more tests on it. If you want to get a look at it, maybe you could allow more than one monitor on your version as well. Now, I need to finish the DeviceFound and DeviceLost endpoints and I think it will be good to go. regards, |
It looks like you are still calling |
I made the last commit with those changes.... I'm implementing the object manager at the root level, but my root level is the uuid. The AdvertisementMonitor1 interface is one level above the uuid... that allows you to have multiple monitors. object manager -> /org/bluez/bluer/monitor/4e7adc5601864010bf393486740bbe92
regards, |
Yeah, I guess that works, but it doesn't seem to be the how the advertisement monitor API is intended to be used. The documentation implies that you are supposed to create a single root object manager per application and then create multiple monitors underneath that, using the object manager signals to tell BlueZ that they were added/removed. |
You are right, and you made me see things from a different perspective. Looking at the API documentation, we must register the root endpoint once and add the AdvertisementMonitor1 interface underneath it multiple times. Instead, we are adding the root endpoint for every monitor we register. And this is also the problem with the crossroad. Every time we add the same path again, it replaces the old one and loses the previous child structure. In the end, it will have only the last monitor as a child, and the previous ones will stop working. With that in mind, I made another proposal, one where we register the monitor once and then add as many rules as we want. I created a new branch for it: And here is the code I used to try it out.
With this code, I have been able to receive events for both monitors.
And the dbus objects's paths are now following what has been suggested in the API documentation. PS: I borrowed some pieces of your code, especially the one that handles the or_patterns, which are much better than mine. Thanks for that. regards, |
Is this issue still open? I'm hoping to use this lib for essentially beacon advertisements, so it seems like this issue might be impactful for me? |
I believe it is still open. I am still waiting for feedback. You could get my branch, update it and use it. I've been using it for a while now, and it works well. Regards |
@otaviojr I got feedback pretty quickly for my (unrelated) change once I actually made a MR. Would you be willing to make a MR of your branch? If not, I can make an MR from a copy of your branch on my fork, so I can handle the feedback and make appropriate updates. |
Could you please send a PR if you would like a review? This makes it easier for everyone. |
OK, I made an MR on @otaviojr 's behalf... |
If @surban would be interested, I can move this MR to my own fork and clean up the commit log as well :-) |
Sorry for the delay, but thanks. If you need something, let me know... About the commit logs, I developed them on a remote host and used git to sync code... :-( Can be cleaned |
# This is the 1st commit message: BLE Passive Scanning # This is the commit message #2: monitor # This is the commit message bluez#3: monitor # This is the commit message bluez#4: monitor # This is the commit message bluez#5: monitor # This is the commit message bluez#6: monitor # This is the commit message bluez#7: monitor # This is the commit message bluez#8: monitor # This is the commit message bluez#9: monitor # This is the commit message bluez#10: monitor # This is the commit message bluez#11: monitor # This is the commit message bluez#12: monitor # This is the commit message bluez#13: monitor # This is the commit message bluez#14: monitor # This is the commit message bluez#15: monitor # This is the commit message bluez#16: monitor # This is the commit message bluez#17: monitor # This is the commit message bluez#18: monitor # This is the commit message bluez#19: monitor # This is the commit message bluez#20: monitor # This is the commit message bluez#21: monitor # This is the commit message bluez#22: monitor # This is the commit message bluez#23: monitor # This is the commit message bluez#24: monitor # This is the commit message bluez#25: monitor # This is the commit message bluez#26: monitor # This is the commit message bluez#27: monitor # This is the commit message bluez#28: monitor # This is the commit message bluez#29: monitor # This is the commit message bluez#30: monitor # This is the commit message bluez#31: monitor # This is the commit message bluez#32: monitor # This is the commit message bluez#33: monitor # This is the commit message bluez#34: monitor # This is the commit message bluez#35: monitor # This is the commit message bluez#36: monitor # This is the commit message bluez#37: monitor # This is the commit message bluez#38: monitor # This is the commit message bluez#39: monitor # This is the commit message bluez#40: monitor # This is the commit message bluez#41: monitor # This is the commit message bluez#42: monitor # This is the commit message bluez#43: monitor # This is the commit message bluez#44: monitor # This is the commit message bluez#45: monitor # This is the commit message bluez#46: monitor # This is the commit message bluez#47: monitor # This is the commit message bluez#48: monitor # This is the commit message bluez#49: monitor # This is the commit message bluez#50: monitor # This is the commit message bluez#51: monitor # This is the commit message bluez#52: monitor # This is the commit message bluez#53: monitor # This is the commit message bluez#54: monitor # This is the commit message bluez#55: monitor # This is the commit message bluez#56: monitor # This is the commit message bluez#57: monitor # This is the commit message bluez#58: monitor # This is the commit message bluez#59: monitor # This is the commit message bluez#60: monitor # This is the commit message bluez#61: monitor # This is the commit message bluez#62: monitor
@jhartzell42 I've cleaned all commit logs at https://github.com/otaviojr/bluer/tree/monitor1 branch Can you change your pull request? |
I can't retarget it to a different branch, and I can't modify the branch I'm using, as it's a pull request literally from your fork. Could you possibly make your own pull request from monitor1?? If not, I'll delete the one I have, make my own fork, migrate your new branch over, and make a new pull request. |
@jhartzell42 done |
PR merged. |
I'm trying to use bluer on a raspberry pi to scan for advertising BLE devices. In doing some research, I'm fairly certain that bluer only supports active (ie. scan request) discovery, and that there is code in BlueZ to support passive scanning (used in hcitool lescan, for example), but there isn't anything in bluer to give access to passive scanning.
The text was updated successfully, but these errors were encountered: