Azure / azure-spatial-anchors-samples

Azure Spatial Anchors sample code
Other
293 stars 138 forks source link

Unable to find/use Bluetooth Beacons on IOS - Unity #287

Open wyliefoxxx opened 3 years ago

wyliefoxxx commented 3 years ago

I'm sorry to pose a bit of help question, but after 20+ hours of rearranging code and studying the docs to solve this specific issue, I'm unsure whether this is a question or actually a bug (Perhaps its a request for clarification in the documentation).

Because of the price constraints, using 'anchorLocateCriteria.NearDevice' with MaxResultCount = 1 is the only realistic way to initially localize a device. We've been experimenting continuously for over a year now with generally poor cross-mobile (Android - IOS) results when GeoLocation is the only Sensor data used (Wifi helps Android anchor location times, but still cannot be used by IOS platforms). Thus, for indoor environments, we're hoping Bluetooth Beacons will optimize NearDevice location.

Unfortunately, it seems, we are unable to get our test devices (IOS or Android) to recognize our Bluetooth beacons, no matter how we tinker with the information available.

Our android manifest contains permission requests for: android.permission.ACCESS_COARSE_LOCATION android.permission.BLUETOOTH android.permission.BLUETOOTH_ADMIN as well as android.permission.ACCESS_BACKGROUND_LOCATION (for the sake of testing purposes. Along with the manual background permission granted steps on Android 10+)

For our IOS build, we've followed the instructions here (iOS: Add the "Privacy - Location When In Use Usage Description" key to Info.plist)

The general flow of our C# code within unity goes as such:


//** On App Start locationProvider = new PlatformLocationProvider();

if UNITY_ANDROID

bool p = Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH"); if (!p) { Permission.RequestUserPermission("android.permission.BLUETOOTH"); }

endif

//-> Repeated with "BLUETOOTH_ADMIN" and "ACCESS_COARSE_LOCATION" permissions

//** After confirmation of permission grants, and successful CreateSessionAsync() locationProvider.Sensors.BluetoothEnabled = true; locationProvider.Sensors.KnownBeaconProximityUuids = new[] { "d546df97-4757-47ef-be09-3e2dcbdd0c77", "fda50693-a4e2-4fb1-afcf-c6eb07647825" }; Debug.Log(locationProvider.BluetoothStatus) // Prints: "MissingSensorFingerprintProvider" cloudManager.Session.LocationProvider = locationProvider; cloudManager.Session.LocationProvider.Start(); // Seems to work the same with/without this await cloudManager.StartSessionAsync();

//** When user creates watcher anchorLocateCriteria = new AnchorLocateCriteria(); NearDeviceCriteria nearDeviceCriteria = new NearDeviceCriteria(); nearDeviceCriteria.DistanceInMeters = 10; nearDeviceCriteria.MaxResultCount = 1; anchorLocateCriteria.NearDevice = nearDeviceCriteria;

Debug.Log(locationProvider.BluetoothStatus) // Prints: "NoBeaconsFound" // WifiStatus and GeoLocation are usually 'Available' at this point

// Within a coroutine yield return currentWatcher = cloudManager.Session.CreateWatcher(anchorLocateCriteria);


The watcher that is created is capable of locating anchors eventually using the other sensor data, but no matter how close to the bluetooth beacons we are, or how much time has passed, the location provider's BluetoothStatus is always 'NoBeaconsFound'

We've triple checked that our Bluetooth Beacons are set correctly, using IBeacon UUID's in the form of: d546df97-4757-47ef-be09-3e2dcbdd0c77 Or Eddystone Advertisements with UID/Namespace's in the form of: d546df973e2dcbdd0c77 or d546df973e2dcbdd0c77123456789012 .. and are functioning properly, and detectable by each test device.

We've tried feeding KnownBeaconProximityUuids many different forms of the Beacon UUIDs and UIDs, but one would expect the form listed in the Course Relocation docs to work (22e38f1a-c1b3-452b-b5ce-fdb0f39535c1) with IBeacon advertisements (at least on IOS devices)

I've rearranged the code in many, many different ways, but cannot find any way to detect the Beacons and get anything other than a 'NoBeaconsFound' status on our Android or IOS test devices.

One thing to note, is when attempting to get/read the KnownBeaconProximityUuids from the active session (cloudManager.Session.LocationProvider.Sensors.KnownBeaconProximityUuids), android gives this error, but I assume its more of a 'yet to be implemented' thing, rather than a bug: E/Unity: NotImplementedException: . Request CV: . Response CV: . at Microsoft.Azure.SpatialAnchors.NativeLibraryHelpers.CheckStatus (System.IntPtr handle, Microsoft.Azure.SpatialAnchors.status value) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Azure.SpatialAnchors.SensorCapabilities.get_KnownBeaconProximityUuids () [0x00000] in <00000000000000000000000000000000>:0

The beacons we are using are: Feasycom FSC-BP103B Bluetooth 5.1 Proximity Low Energy Beacon LE iBeacon Support Eddystone iBeacon and AltBeacon

We are using: Unity 2020.3.15f2 MRTK 2.7.2 ASA 2.10.2 Mixed Reality OpenXR Plugin 1.0.1 With the latest ARFoundation, ARKit, and ARCore packages (4.1.7) *The android project also currently implements the workarounds outlined in https://github.com/Azure/azure-spatial-anchors-samples/issues/283

Testing Devices: Samsung Galaxy S9 (targeting API 30) IPhone 8+ IOS Version 14.7.1

I'm usually not the type to ask for help, but I'm at my wits end on this one. I'm hoping there's just something I'm missing, and that this post will help others in my position as we all push forward deeper into uncharted technological territory, but our project now hinges on the ability to (relatively) quickly find anchors in indoor settings, so it's of upmost importance for us to get this system working.

I greatly appreciate all the amazing work that's gone into making this technology possible, and really appreciate any help or input on this issue

msftradford commented 3 years ago

Thanks for reaching out @wyliefoxxx! Let me take this to the coarse relocalization experts on the team to see if anything sticks out to them.

wyliefoxxx commented 3 years ago

Thanks a lot @msftradford, I've done my best to avoid troubling the team over the last year of development, but am finally completely and utterly stumped.

msftradford commented 3 years ago

A quick question, have you attempted to modify the ASA Unity Sample that uses coarse relocalization to reference your bluetooth beacons? Did you notice any change in behavior?

wyliefoxxx commented 3 years ago

I apologize, I had no luck with the demo setup initially, but after reprobing it today, I was able to use it to successfully establish a bluetooth connection, demonstrated by a green light in the demo. I wouldn't have posted the question on here had I been able to get it to work previously.. I think my tinkering with the bluetooth beacon devices settings in the time since initially testing the demo script might have done the trick.

Using, what I see to be the the same sequence of events, in our project, however, still does not yield any bluetooth connection. I suppose I'll continue tinkering with our setup some more, now that I've managed to get the demo script to work, and report back with any findings, hopefully just with some advice for anyone facing a similar situation. Again, my apologies for a premature issue post.

The primary difference between our setup and demo script is in the inclusion of the MRTK. I'll do what I can to look for other discrepancies and post my findings.

Thanks again for the top-notch support!

msftradford commented 3 years ago

@wyliefoxxx that is wonderful to hear! Please do keep us updated with your findings and feel free to close the issue once everything is resolved.

wyliefoxxx commented 3 years ago

Well, now I'm feeling quite embarrassed about solving what ended up being a simple problem on my end involving improperly passed UUIDs. My recent experience with the 2.10.2 Android workaround lured me into a false sense of 'maybe its not my fault'. I hope this issue didn't make it too far on your side. Hopefully my code flow from above helps someone in the future!

wyliefoxxx commented 3 years ago

.... aaactually... I managed to get the sample project and our project set up and functioning with bluetooth beacons on Android... however... now, we cannot get the sample Course Relocation project (or our project) to recognize any known bluetooth beacons on IOS.

I really do believe we've followed the instructions precisely, with correct permissions and packages all set. The demo project works as it should, with GPS enabled, but Bluetooth is never reported as available. I can confirm, that the status is initially 'MissingSensorFingerprintProvider' immediately after SensorConfiguration, but then remains in the 'NoBeaconsFound' for the remainder of use.

After getting the sample project to work on Android, I'm fairly certain we've configured and are using the Beacons with their corresponding UUIDs correctly in the sample project for IOS. I hate to reopen this issue after a bit of cry-wolf situation, but It's been quite a hair-puller narrowing these issues down (luckily I'm bald), and I am once again out of options on IOS.

Can anyone confirm the functionality of Bluetooth on IOS with the ASA Unity Sample - Course Relocation example? If not, there might be an actual problem.

We're using: Unity 2020.3.15f2 ASA 2.10.2 IPhone 8+ IOS Version 14.7.1

msftradford commented 3 years ago

Thanks for letting us know @wyliefoxxx and really appreciate the detail that you've provided. Let me talk to the team about the iOS bluetooth implementation.

msftradford commented 3 years ago

@wyliefoxxx, I'd love to get your feedback on how we can better document the expected UUID format. Is there something that we could have included in the sample code or would it have been useful to add some detail to our coarse reloc concept page or reference docs. Thanks!

wyliefoxxx commented 3 years ago

Thanks a lot, we've done what we can to get the demo working on IOS. I do hope (for the teams sake) that it's still just an error on my part (I apologize in advance if it is), and confirmation from anyone that the demo course relocation scene works on IOS is probably all I'll need, but yea I appreciate the help, and maybe it is some kind of bug..

My one suggestion for the docs you mentioned, would be to have an explicit example of an Eddystone UID along with the IBeacon style UUID's listed in the help documentation. It's easy to get lost in Eddystone namespaces and instance byte rearrangement, as it's my understanding (although I may be wrong in this) that Eddystone UIDs appear in a different format than IBeacon UUID's. This lead to quite a bit of confusion, trying different combinations on my beacons and in the code. Some (even commented out) examples of acceptable Eddystone UIDs in the sample code or concept page would be helpful.

That's my best suggestion, but I might have a few more by the time I get the beacons working on IOS.. but again, I really appreciate the technological wizardry going on over there, and the support, and really don't have any complaints :)

msftradford commented 3 years ago

Hey @wyliefoxxx, wanted to let you know that we've opened an investigation into this (#35573617). Will keep you updated as soon as we learn things.

wyliefoxxx commented 3 years ago

Thanks a lot!

jelmerS2 commented 1 year ago

I'm also having this issue. iOS returns "no beacons found" while in an environment with many becaons of which the UUIDs I added to the CoarseRelocSettings. The app did ask for bluetooth permissions which I gave.

Varnauld commented 1 year ago

@XiangyuL-Microsoft could you look into this issue please? thank you!