Azure / azure-spatial-anchors-samples

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

Unable to create Coarse Reloc Anchor with AppProperties when on LTE data #171

Closed christopheryang90 closed 4 years ago

christopheryang90 commented 4 years ago

When on LTE (not wifi) and appProperties are added to the anchor, saving the anchor gives following error: When creating a new anchor while connected through LTE data, my script gives this error: AndroidPlayer(ADB@127.0.0.1:34999) InvalidOperationException: Message: Unexpected response code. Request CV: LqZqMBSxSSGCmEAAzvirNw. Response CV: jwQWHBifx0aeMc991chTyw.0. HTTP Error: 400.. Request CV: LqZqMBSxSSGCmEAAzvirNw. Response CV: LqZqMBSxSSGCmEAAzvirNw and jwQWHBifx0aeMc991chTyw.0. at Microsoft.Azure.SpatialAnchors.NativeLibraryHelpers.CheckStatus (System.IntPtr handle, Microsoft.Azure.SpatialAnchors.status value) [0x00131] in /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.SDK/Plugins/Common/AzureSpatialAnchorsBridge.cs:7103 at Microsoft.Azure.SpatialAnchors.CloudSpatialAnchorSession+<>c__DisplayClass82_0.<CreateAnchorAsync>b__0 () [0x00001] in /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.SDK/Plugins/Common/AzureSpatialAnchorsBridge.cs:9240 at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in <7d97106330684add86d080ecf65bfe69>:0 at System.Threading.Tasks.Task.Execute () [0x00010] in <7d97106330684add86d080ecf65bfe69>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <7d97106330684add86d080ecf65bfe69>:0 at Microsoft.Azure.SpatialAnchors.CloudSpatialAnchorSession+<CreateAnchorAsync>d__82.MoveNext () [0x00058] in /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.SDK/Plugins/Common/AzureSpatialAnchorsBridge.cs:9238 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <7d97106330684add86d080ecf65bfe69>:0 at Microsoft.Azure.SpatialAnchors.Unity.SpatialAnchorManager+<CreateAnchorAsync>d__45.MoveNext () [0x000fe] in /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.SDK/Scripts/SpatialAnchorManager.cs:872 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <7d97106330684add86d080ecf65bfe69>:0 at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <7d97106330684add86d080ecf65bfe69>:0 at Microsoft.Azure.SpatialAnchors.Unity.Examples.DemoScriptBase+<SaveCurrentObjectAnchorToCloudAsync>d__41.MoveNext () [0x001a0] in /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.Examples/Scripts/DemoScriptBase.cs:459 UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object) UnityEngine.DebugLogHandler:LogException(Exception, Object) UnityEngine.Logger:LogException(Exception, Object) UnityEngine.Debug:LogException(Exception) Microsoft.Azure.SpatialAnchors.Unity.Examples.DemoScriptBase:OnSaveCloudAnchorFailed(Exception) (at /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.Examples/Scripts/DemoScriptBase.cs:369) Microsoft.Azure.SpatialAnchors.Unity.Examples.TestScript:OnSaveCloudAnchorFailed(Exception) (at /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.Examples/Scripts/TestScript.cs:656) Microsoft.Azure.SpatialAnchors.Unity.Examples.<SaveCurrentObjectAnchorToCloudAsync>d__41:MoveNext() (at /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.Examples/Scripts/DemoScriptBase.cs:480) System.Runtime.CompilerServices.MoveNextRunner:InvokeMoveNext(Object) System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean) System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object, Boolean) System.Runtime.CompilerServices.MoveNextRunner:Run() System.Threading.Tasks.AwaitTaskContinuation:InvokeAction(Object) System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&) System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run(Task, Boolean) System.Threading.Tasks.Task:FinishContinuations() System.Threading.Tasks.Task:FinishStageThree() System.Threading.Tasks.Task:FinishStageTwo() System.Threading.Tasks.Task:Finish(Boolean) System.Threading.Tasks.Task1:TrySetException(Object) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:SetException(Exception) System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetException(Exception) Microsoft.Azure.SpatialAnchors.Unity.<CreateAnchorAsync>d__45:MoveNext() (at /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.SDK/Scripts/SpatialAnchorManager.cs:872) System.Runtime.CompilerServices.MoveNextRunner:InvokeMoveNext(Object) System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean) System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object, Boolean) System.Runtime.CompilerServices.MoveNextRunner:Run() System.Threading.Tasks.AwaitTaskContinuation:InvokeAction(Object) System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&) System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run(Task, Boolean) System.Threading.Tasks.Task:FinishContinuations() System.Threading.Tasks.Task:FinishStageThree() System.Threading.Tasks.Task:FinishStageTwo() System.Threading.Tasks.Task:Finish(Boolean) System.Threading.Tasks.Task1:TrySetException(Object) System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetException(Exception) System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetException(Exception) Microsoft.Azure.SpatialAnchors.d82:MoveNext() (at /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.SDK/Plugins/Common/AzureSpatialAnchorsBridge.cs:9238) System.Runtime.CompilerServices.MoveNextRunner:InvokeMoveNext(Object) System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean) System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object, Boolean) System.Runtime.CompilerServices.MoveNextRunner:Run() System.Threading.Tasks.<>c:<.cctor>b7_0(Object) UnityEngine.WorkRequest:Invoke() (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:115) UnityEngine.UnitySynchronizationContext:Exec() (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:74) UnityEngine.UnitySynchronizationContext:ExecuteTasks() (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:95)

(Filename: /Users/chryang2/Documents/GitHub/WiFi-AR/Assets/AzureSpatialAnchors.SDK/Plugins/Common/AzureSpatialAnchorsBridge.cs Line: 7103)

`

bucurb commented 4 years ago

Could you share the sensors you have enabled? Namely I'm looking for the code you have similar to this:

// Configure location provider to use the allowed sensors
SensorCapabilities sensors = locationProvider.getSensors();
sensors.setGeoLocationEnabled(hasAnyLocationPermission);
sensors.setWifiEnabled(isWifiOn);
sensors.setBluetoothEnabled(isBluetoothOn);
christopheryang90 commented 4 years ago

If I remove the code where I add AppProperties, then I can save Anchors on LTE, and I can only save anchors with AppProperties when on Wifi. Would sensor permission be related to this behavior?

I don't have any of those exact lines in my script, The only place some of the functions you shared (such as "setWifiEnabled") show up in my project is the SDK folder, which I have not touched at all. My script uses configureSensors function from the example as shown below. '

   private void ConfigureSensors()
    {

        locationProvider.Sensors.GeoLocationEnabled = SensorPermissionHelper.HasGeoLocationPermission();

        locationProvider.Sensors.WifiEnabled = SensorPermissionHelper.HasWifiPermission();
        locationProvider.Sensors.BluetoothEnabled = SensorPermissionHelper.HasBluetoothPermission();

        locationProvider.Sensors.KnownBeaconProximityUuids = CoarseRelocSettings.KnownBluetoothProximityUuids;

    }

' Also a side question, does Coarse Relocation watcher update the query as I walk around with my device? If so, what frequency does it update by? I'm just checking to see if I need to manually start/stop the watcher if I'm moving beyond the nearDeviceCriteria.distance

I appreciate everyone's time and help!

bucurb commented 4 years ago

Your app should have some permissions in its manifest, the code above seems to enable all sensors you gave permission to. What do you have enabled in your manifest?

Yes, Coarse reloc will send new sensor readings from time to time, as soon as it detects they've changed by more than a small threshold. You should be able to just keep the watcher going.

christopheryang90 commented 4 years ago

Actually, I just encountered the same error while running the sample Coarse Reloc script on LTE. It seems like this error happens occasionally on the sample script, but almost always on my own script (at least so far today).
AndroidPlayer(ADB@127.0.0.1:34999) RestClient::CreateNeighborhoodAnchorAndSpatialAnchorAsync - HTTP Response Status Code: 400. ReqCV: Z7F6gXi7RNC9kBKokpfRhA. RespCV: C3tdb1cEcE6+6/BafOzEUA.0.

This is the manifest file I found under Assets/plugins/android in my Unity project, it should be whatever the example project provided:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.microsoft.azure.spatialanchors.examples.unity.helloar"
    xmlns:tools="http://schemas.android.com/tools"
    android:installLocation="preferExternal">
  <supports-screens
      android:smallScreens="true"
      android:normalScreens="true"
      android:largeScreens="true"
      android:xlargeScreens="true"
      android:anyDensity="true"/>

  <application
      android:theme="@style/UnityThemeSelector"
      android:icon="@mipmap/app_icon"
      android:label="@string/app_name">
    <activity android:name="com.unity3d.player.UnityPlayerActivity"
              android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
  </application>

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
  <uses-permission android:name="android.permission.BLUETOOTH"/>
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
</manifest>
bucurb commented 4 years ago

Yes, thank you, you've bluetooth on, and yes, it should happen randomly, i.e. every time you get a ping from a BLE beacon. For a real quick fix with nothing from our side, can you take-out the bluetooth permissions from your manifest. That should fix it if my diagnosis is correct ;). Let me know how it goes.

christopheryang90 commented 4 years ago

Yes, after removing the bluetooth permissions from the manifest, I'm able to save cloud anchors consistently. Thanks a ton!