-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
Track iPhones via BLE #309
Comments
How feasible would this be? Am I understanding correctly that an app would be required? Haven’t done any Swift coding in a while have done just about enough to potentially make it work if room-assistant will definitely work with it. |
As far as I understand it right now we would need an app that uses the Core Bluetooth APIs in peripheral mode. The app should register a BLE service that can also be called in the background (needs some special setting). The service should be advertised under a known name, so that we can discover it from room-assistant. After connecting to it it should provide a static ID (possibly protected by a password for privacy reasons). The static ID should probably be configurable in the app UI. I have no clue if it would be allowed into the App Store like this though. |
Crownstone goes a bit more into detail on how to achieve this here. In contrast to what was discussed on reddit this does not require connections to the device. I spent some time writing a sample test app in Swift, which can now advertise stuff in the background. I now need to test my sample app to see if I can reproduce the findings from the link above. |
Another update for the interested people: I managed to get this working! There still are some open tasks and the whole functionality isn't perfect yet, but it can correctly identify my test iPhones BLE advertisements without pairing even when it's in standby. I ended up limiting it to just the initial idea, as the additional information from Crownstone wouldn't add much benefit for the room-assistant functionality. Next steps: clean up some things, make the app a bit prettier and then figure out how to make it available via TestFlight. |
That’s awesome!
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Heiko Rothe <notifications@github.com>
Sent: Monday, October 26, 2020 1:19:50 AM
To: mKeRix/room-assistant <room-assistant@noreply.github.com>
Cc: Subscribed <subscribed@noreply.github.com>
Subject: Re: [mKeRix/room-assistant] Track iPhones via BLE (#309)
Another update for the interested people: I managed to get this working! There still are some open tasks and the whole functionality isn't perfect yet, but it can correctly identify my test iPhones BLE advertisements without pairing even when it's in standby. I ended up limiting it to just the initial idea, as the additional information from Crownstone wouldn't add much benefit for the room-assistant functionality.
Next steps: clean up some things, make the app a bit prettier and then figure out how to make it available via TestFlight.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FmKeRix%2Froom-assistant%2Fissues%2F309%23issuecomment-716155897&data=04%7C01%7C%7C73456204ec31463e5a7408d878f108e2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637392323908311275%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=tvopQuW4vBSJLA0YIGP3IFrcyXZJrjABMMZj68Awa6Y%3D&reserved=0>, or unsubscribe<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAEVSDTSWGZ43UINOPYYST53SMQXYNANCNFSM4SYVHGDA&data=04%7C01%7C%7C73456204ec31463e5a7408d878f108e2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637392323908311275%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Kl4ig%2Fy2nJxJaNyj0sitP%2BOYnQYGtU8bx81qAIFzGMc%3D&reserved=0>.
|
I've submitted the app version I had to TestFlight for review, but since the UI part is very simple and it is more or less just a tool for setting background Bluetooth settings I fear that it may be rejected on the grounds of not providing a "minimum functionality". I still wanted to see if it's enough for TestFlight in this first version. If this fails I'll have to think of some features I could add to the app (maybe viewing current RSSI levels for easier tuning?). Implementing those will then take some more time, as I'm not really versed in Swift or iOS development. |
What about adding as part of the Home Assistant Companion App? |
We could ask, but I don't think they would want it in there. The Home Assistant app currently asks for no Bluetooth permissions, this requires "Bluetooth always" permissions. I feel like it would be hard to argue to include this code and request additional permissions for a project which is not under their control. At least this could be a fun exercise for getting into Swift and all that stuff, even if it takes some time. |
Good news! The app has been approved for beta testing via TestFlight by Apple. I will distribute a new beta release of room-assistant and the app link soon. |
I would love to help beta test. |
# [2.13.0-beta.1](v2.12.0...v2.13.0-beta.1) (2020-11-11) ### Bug Fixes * **bluetooth:** attempt adapter reset on LE timeouts ([386ef37](386ef37)) ### Features * **bluetooth-low-energy:** allow iOS tracking via BLE ([17d537d](17d537d)), closes [#309](#309) * **bluetooth-low-energy:** share discovered apps with cluster ([188e76c](188e76c))
🎉 This issue has been resolved in version 2.13.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
You can try this now! You will need to install the beta version of room-assistant and the app on any device you want to track. The app is available through TestFlight here: https://testflight.apple.com/join/OpCkeHf8 Would love to hear any feedback you might have. |
Hi
Have this installed and whilst other BLE devices are showing up in the logs, there’s no sign of either of my iOS devices ... not the iPad Pro or my iPhone 11
I granted Bluetooth permissions to the TestFlight app / RA app in TestFlight but I’m not convinced its actually doing any advertising currently
Thoughts?
–
Jon Morby
… On 11 Nov 2020, at 20:40, Heiko Rothe ***@***.***> wrote:
You can try this now! You will need to install the beta version of room-assistant and the app on any device you want to track. The app is available through TestFlight here: https://testflight.apple.com/join/OpCkeHf8
Would love to hear any feedback you might have.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I only have a single device to test with, but am noticing the same behaviour. Grep on output for the first three chars of the ID displayed in the app doesn't return anything. Also a feature suggestion, it'd be nice to be able to copy the ID from the app! Thank you tons for the hard work and excited to see this happening! |
Are you on the latest room-assistant beta version as well (v2.13.0-beta.1)? You should see some logs saying "attempting app discovery for tag xyz", hopefully followed by a message that companion app was discovered with the IDs that you are shown in the app. Sometimes it also helps to turn Bluetooth off and then on again in the settings (not the control center!). You can also try and see if the service is being advertise correctly by installing the nRF Connect app on an extra device (e.g. your iPad), then scanning and connecting to the device that you want to track (e.g. iPhone). After connecting you can swipe over to the left on the device details page, which should show an attribute table. Does this table contain the room-assistant service (UUID starting with 5403C8A7) and characteristic (UUID starting with 21C45F33)? If you click the little down arrow on that characteristic, does it show some value? |
Running 2.13.0-beta.1, however I am not seeing any logs stating that it is attempting app discovery for tag xyz. Do I need to add the UUID to the whitelist even if I have not seen it in the logs with an empty whitelist? How would room-assistant know that the UUID I gave it is for the companion app? |
Have added the UUID to the whitelist, configuration looks like this now: global:
integrations:
- homeAssistant
- bluetoothLowEnergy
homeAssistant:
mqttUrl: 'mqtt://192.168.1.xxx:1883'
mqttOptions:
username: mqtt-user
password: pass
bluetoothLowEnergy:
hciDeviceId: 0
whitelist:
- id-in-companion-app-with-dashes But I still do not see companion app logs. |
The ID for the companion app looks different than MAC addresses, it shouldn't make much of a difference though. I suspect that an assumption that I have made to limit the amount of devices it tries to discover from isn't applicable for the real world and only worked for my test device. You can help me try this out with some manual editing of the code. If you are on a Pi Zero, you can edit I will also see if I can test with some more devices. EDIT: After editing the file you need to restart room-assistant of course. |
Set it to 1 and it was attempting connections with everything more or less. Set it to 6 and it does attempt a couple unsuccesful connections but most importantly it discovers the companion app. Testing a little bit further now, I don't see the MQTT topic I need to add to home assistant to add that device to home-assistant. I also forgot how to debug that element. This is all I see in the logs (verbose off):
|
Alright, seems like we need to fine-tune that number in the next versions. I will put out a new beta with the value decreased later today so that this at least works without manually editing stuff. The entity should appear automatically in HA as long as the ID is in the whitelist, at least if you have auto discovery enabled in HA. The state topic for the sensor should be in room-assistant/sensor/ble-UID-VERY-LONG-AND-MANY-DASHES/state. |
Morning
After reading that counter to 1 I can also confirm that the companion app is detected and so far it seems to be working as anticipated!
Thanks for adding this functionality, truly amazing!
–
Jon Morby
… On 12 Nov 2020, at 11:50, Heiko Rothe ***@***.***> wrote:
Alright, seems like we need to fine-tune that number in the next versions. I will put out a new beta with the value decreased later today so that this at least works without manually editing stuff.
The entity should appear automatically in HA as long as the ID is in the whitelist, at least if you have auto discovery enabled in HA. The state topic for the sensor should be in room-assistant/sensor/ble-UID-VERY-LONG-AND-MANY-DASHES/state.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I believe I have everything setup correctly as it stands, however I am not seeing the entity appear in the integration - despite other sensors (cluster leader and cluster size) being created successfully. In my logs, I see this:
Indicating that the companion app was discovered by room-assistant. I have since deleted the MQTT integration and restarted the entire process twice, but to no avail. Both Rasperry Pies have been restarted too. The config file for both is this global:
integrations:
- homeAssistant
- bluetoothLowEnergy
homeAssistant:
mqttUrl: 'mqtt://192.168.1.232:1883'
mqttOptions:
username: mqtt-user
password: mqtt-pass
bluetoothLowEnergy:
hciDeviceId: 0
whitelist:
- uuid-very-long-many-dashes-but-lowercase Listening for events with topic |
The issue lies in the fact that unlike the other BLE entities, these have to be upper case in the config, as such: global:
integrations:
- homeAssistant
- bluetoothLowEnergy
homeAssistant:
mqttUrl: 'mqtt://192.168.1.232:1883'
mqttOptions:
username: mqtt-user
password: mqtt-pass
bluetoothLowEnergy:
hciDeviceId: 0
whitelist:
- UID-VERY-LONG-AND-MANY-DASHES |
Predictably, we're now hitting Apple's restriction regarding BLE tracking. If the iPhone is locked, no more advertisements are made. I imagine there is no workaround for this as I'd expect we would have otherwise seen functional "Track and trace" type apps not using the Apple SDK for it. Unless we can initiate a sort pairing request that would allow locked tracking, this is probably the best we'll get. Other than that, I am seeing significantly more robust tracking in a small flat. Previously on Bluetooth Classic, I would constantly be jumping from room to room, which is not the case now, as the BLE integration tracks the phone much better. |
This issue from a different but very similar project (track and trace basically), indicates that it might be possible by flipping the relationship once the app goes into the background: instead of asking the iPhone to advertise, room-assistant should instead broadcast beacons whose handling can be delegated to iOS. The companion app would subsequently have to emit the mosquito packet itself (if I'm understanding correctly). EDIT: I'm only guessing, but would it be possible to request to be woken-up by Apple if the device is moving? EDIT2 (apologies I'm basically thinking out loud): Now that we have a companion app, I am wondering if it is not possible to flip the relationship and have the app report its location, rather than the Raspberry Pi? eg, we would make each instance of room-assistant a beacon and have the iPhone send a mosquitto packet to home-assistant telling it which room (beacon) it is closest to. From the thread linked above, this seems doable even with the app in the background. EDIT3: The app also goes into the background randomly, even with the phone unlocked. |
I'm sorry to hear that you guys are having trouble with beta.5. This task is really tricky for me - I felt like we're really close to something usable for weeks now, but I can't seem to figure the last steps out. That being said, I just found a bug in the app today that prevented me from the actually seeing which device has the app installed before connecting... which then led me to implement this brute-force approach of just connecting to anything Apple and checking. I will re-write room-assistant to account for this newly found data, which should reduce the amount of required connections heavily. I will also try to re-trace some of the changes that may have lead to the worse detection issues that you guys reported. As for BT Classic: you will need to raise the interval for BT Classic to at least 20 for it to work in tandem with BLE in beta.5. I will improve on this in the next version(s). @riddledaxis If you don't specify |
@mKeRix I think the problem was because I had configured room assistant to run as a service when I set it up originally with BT Classic. I was stopping room assistant with systemctl stop room-assistant, not room-assistant.service. I was also starting room assistant with room-assistant and not systemctl start room-assistant.service and that is why I think it didn't pick up the correct config without the -c flag I have now restarted the service and I am waiting to see if it is more reliable. I also set up a pi zero W yesterday with the room-assistant.service on beta.5 and that seems to be pretty reliable at the moment. |
I published another beta release - this will limit connection attempts to iOS devices that actually advertise having the app installed, instead of connecting to any Apple device that was found in the vicinity like before. Note that for this beta to work you will need to install the latest build from TestFlight (v0.1.0, build 4) and open the room-assistant companion app at least once on each device before it will be detected. Let me know how things are looking for you with this beta. It's not perfect, but I've been happy with what I've seen on my test setup so far. |
Thanks for your efforts @mKeRix. Will give this a try shortly. |
@mKeRix, thank you for the new beta. I am running it on both my pi's and at the moment (touches wood), it is all running ok. Will update in a couple of days. |
This latest update (beta 6 and build 4 of the iOS app) is by far the best and I have it working fairly reliably, up until now BLE trackinf would only work for very short periods. Thanks so much for your work on this @mKeRix |
Running beta 6 with the latest test-flight. Couple of questions.... I'm using bLE with iphones. People jump from room to room quite often. Also I have a bLE device on teh family dog (a fitness tracker type thing) Thanks for your hard work on this ! |
@B-Hartley If it's only about intermittent jumps but an otherwise correct long "correct" state I would recommend to turn on debouncing. For this you would need to set the time to whatever your longest intermittent incorrect state was +10-20%. If it's a correct state that has many small incorrect blips rolling average would be a good choice. You can also combine both for further experiments. You can find the entity ID via the entities endpoint of the room-assistant API or the verbose logs (no easier way yet, sorry - I want to find something better for this!). For the tracker I would suggest to just raise the |
Thank you very much. |
# [2.13.0](v2.12.0...v2.13.0) (2021-01-31) ### Bug Fixes * **bluetooth:** attempt adapter reset on LE timeouts ([386ef37](386ef37)) * **bluetooth:** disallow parallel resets ([09d55bd](09d55bd)) * **bluetooth:** further improve adapter stability ([fef1a2c](fef1a2c)) * **bluetooth:** hard reset adapter on timeouts ([112441b](112441b)) * **bluetooth:** improve adapter stability ([1c99d05](1c99d05)) * **bluetooth:** improve adapter stability ([27112a0](27112a0)) * **bluetooth-low-energy:** add timeout for app discovery ([16922ac](16922ac)) * **bluetooth-low-energy:** end app discovery on disconnect ([ac2c13d](ac2c13d)) * **bluetooth-low-energy:** improve app id sharing ([b0b2f7c](b0b2f7c)) * **bluetooth-low-energy:** only disconnect from connected devices ([d54c53d](d54c53d)) * **home-assistant:** do not log binary state updates ([a96b566](a96b566)) * improve companion app detection ([4e75511](4e75511)) * limit classic inquiry lock time ([c1412cb](c1412cb)), closes [#327](#327) ### Features * **bluetooth:** reset deadlocked Bluetooth adapters ([4cdeb24](4cdeb24)) * **bluetooth:** reset stuck Bluetooth adapters ([ab4e940](ab4e940)) * **bluetooth-low-energy:** allow iOS tracking via BLE ([17d537d](17d537d)), closes [#309](#309) * **bluetooth-low-energy:** auto-attempt to recover scanning states ([df72629](df72629)) * **bluetooth-low-energy:** make regular lists case insensitive ([286bd22](286bd22)) * **bluetooth-low-energy:** only connect to companion app devices ([adc3f23](adc3f23)) * **bluetooth-low-energy:** share discovered apps with cluster ([188e76c](188e76c)) * **entities:** add debounce edge options ([d5b92cf](d5b92cf)), closes [#329](#329) * **home-assistant:** add device tracker discovery ([#425](#425)) ([5e3a727](5e3a727)) * **home-assistant:** add health indicator ([2ab6e42](2ab6e42)) * **home-assistant:** allow disabling of attribute updates ([9d2eb5b](9d2eb5b)) * **logger:** add Kibana log transporter ([076df21](076df21)) * **prometheus:** add metrics ([d6a90ea](d6a90ea)) * **xiaomi-mi:** add device information ([#362](#362)) ([67427d5](67427d5)) * add toggle for heatmap ([60afaa5](60afaa5))
🎉 This issue has been resolved in version 2.13.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
My test setup continued to run well, so I decided to release this outside of the beta. Any further problems with this integration should receive their own, new issues. That way my mind is also freed up a bit and I can work on some other stuff again. 😄 |
The docs weren't updated to link to the app required for this? |
They were for me, although I had to "Reload content". |
The docs website is a PWA atm, which caches its content on first load for quick load times and offline access. To get the refreshed content you need to either hit the button at the bottom right when it pops up or do a hard refresh in your browser. The current TestFlight link is: https://testflight.apple.com/join/OpCkeHf8 |
Running your iPhone app beta version 0.1.0 (8) and sniffing for BLE advertisement by another device Here is what I see BLE Advertised Device found: Name: room-assistant companion, Address: 61:26:43:f8:31:c8, serviceUUID: 5403c8a7-5c96-47e9-9ab8-59e373d875a7, txPower: 8 I have 2 problems
|
The service UUID that is advertised is hard-coded, room-assistant specifically looks for it and reads a characteristic from it. This is needed since advertising a BLE service in the background on iOS doesn't actually advertise the service directly, it just flips a bit in the manufacturer data of the packet. Since the ID is hardcoded we know which bit to look for, otherwise we wouldn't (the mapping algorithm between UUID and bit isn't public). There is nothing special to do for making the app work in the background - you just need to grant the Bluetooth permissions. For the auto toggle feature you also need to allow "location always" access (doesn't actually pull your location with GPS, just watches for beacons). That feature will be reworked or replaced by something else though, so I'd probably stick to leaving it off for now. Somebody else also posted about it not working when the phone was locked a while ago if I remember correctly, but I wasn't able to reproduce it. Which iPhone model are you trying to run the app on? |
@mKeRix Thanks for the prompt and detailed response. I moved to the released (non TestFlight) version of the app now and also I'm not using my BLE "sniffer" anymore. Instead I installed and run your room-assistant on RPi. Thanks for developing this wonderful tool and the companion app.
Thanks, |
The Pi 2 doesn't have any built-in Bluetooth adapter though - those were only added with the Pi 3 and Pi Zero W? Either way, if it's not too much of a hassle I'd recommend checking if it works better with your other Pi. As for the other stuff, feel free to open separate feature request issues for those. While developing v2.x I already reduced the amount of messages greatly based on previous feedback I've gotten, it should be much lower than any of the other room presence tools out there at the moment (at least for the As for the request stuff - room-assistant already has a REST API to allow for request-response communication, I'm a bit hesitant with adding yet another layer next to REST, web sockets and MQTT that are already there. |
Thank for the prompt and detailed response.
For example: If I'm laying on the couch reading a book for two hours than room-assistant will send out (at current pace) about 12,000 MQTT messages that need to be passed to MQTT broker over the network and processed by Home Automation server. This is absolutely useless for the purpose of presence detection. I urge you to reconsider adding a "radius" attribute in settings and report to MQTT only when a beacon enters or leaves the circular area defined by such radius. Your point of treating all integrations in the same way is a good one and I do respect it. I can't comment further as I'm a novice here and not familiar at all with the other integrations. Per your request I will open a separate issue in "feature requests".
|
@ivanvach, can you use the |
@PeteBa Thanks for the advise. Wouldn't such approach reduce the sensitivity / granularity to change in presence. For example if it is set at 1 message per 5 sec. than if I walk in a room than I'll need to wait up to 5 sec for the presence driven lights to come up. |
Hi, is this app still being tested? If so, can I have a testflight invite please? |
It's in the App Store now. |
Ah, so it is! Thanks!
…Sent from my iPhone
On 9 Jan 2022, at 16:51, B-Hartley ***@***.***> wrote:
It's in the App Store now.
—
Reply to this email directly, view it on GitHub<#309 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ALYN2WEYA4XTOHNACETYB53UVG4IDANCNFSM4SYVHGDA>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Is your feature request related to a problem? Please describe.
BLE tracking is quicker and a bit more reliable than BT Classic tracking. It would be awesome if we could also get this working for iPhones.
Describe the solution you'd like
The idea for this was spawned in a reddit comment thread. It turns out you can make iPhones and Macs (not Watches!) act as a peripheral and advertise a custom service via BLE. For this we need to write our own app. That service can then provide a static ID, which we can tie to the periodically changed random ID. Based on this you can then actually track the iPhone based on its BLE advertisements. Each time we see a new ID advertise our custom service we connect to the service and find the "room-assistant" ID that belongs to the cloaked BLE MAC.
Describe alternatives you've considered
The text was updated successfully, but these errors were encountered: