I'm trying to send GPS-coordinates from an Android device to the Hololens by BLE-advertisments. The problem as far as i see, the events from BluetoothLEAdvertisementWatcher do not trigger on the Hololens.
I have tried copy-paste both this implementation and this on the receiver side, no received event.
This is the current implementation in Unity, i have implementated the same functions in a blank UWP-C# project and deployed directly on the Hololens with the same result.
private void StartWatcher()
{
void OnAdvertisementReceived(object sender, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation
}
void OnAdvertisementStop(object sender, BluetoothLEAdvertisementWatcherStoppedEventArgs eventArgs)
{
Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation
}
try {
BluetoothLEAdvertisementWatcher watcher = new BluetoothLEAdvertisementWatcher();
watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(GetManufacturerData());
watcher.Received += OnAdvertisementReceived;
watcher.Stopped += OnAdvertisementStop;
watcher.Start();
Debeug.Log("Started"); // switched to Write-line on the C#->UWP implementation
} catch (Exception e){
}
}
private BluetoothLEManufacturerData GetManufacturerData()
{
var manufacturerData = new BluetoothLEManufacturerData();
manufacturerData.CompanyId = 0X06EF;
return manufacturerData;
I know the advertisements are sent, becuase if i debug the native UWP-application directly in Visual Studio on the PC(even as ARM64), everything works. The events are triggered.
The watcher.Status
reports "started" on the Hololens
Even if i disable the Bluetooth on the HoloLens while the application are running, the stop-event are not either triggered.
If i check watcher.Status
after i disable the Bluetooth, the status reports aborted but the Stoped-event are not recieved.
The capability is activated following this article
Now to where it gets wierd. During one of my first tries i had my application running on the Hololens as i've tried to remove the pairing between the Android device and HoloLens. The android devices appears as two devices on the Hololens, device name as one and "LE"+MAC as the other. Sometime during the time i was in the Bluetooth settings and removed the two adapters from the cellphone, the HoloLens recieved three separate advertisments. The data in the advertisments was also confirmed from my Android device becuase during my inital tries i parsed the data.
But thats it, i have tried to replicate this for 10 hours today, Pair and unpair the different adapters in different stages while listening for recieve events but without luck. On my PC, it do not matter if the adapters are paired or not.
I have tried both .NET Standard 2.0 and .Net 4.x as API Compatibility Level. I have set breakpoints in both the receive and Stoped event-handler as i was afraid that the calls from the Event-functions was the problem. As far as i see, we never reach the implemented events.
Any suggestion on what might be the next step to check is appreciated.
The Hololens Build is 19041.1144.
Ok, so i can now recevie advertisments on the HoloLens by running the example provedied by Microsoft. I could not receive any events at all and no updates was available in the settings, so i've reinstalled all applications in the Microsoft Store and that seems to be the solution for me. After that and a restart of the HoloLens i was able to recieve advertisements from my PC.
Another tip for other tip for people trying to recieve advertisements on the HoloLens 2. When i was able to receive advertismements from my pc i saw that the advertisments from my Android device was not recieved on the HoloLens, but recieved on the PC. The advertisments on my PC was of type NonConnectableUndirected and from my Android device ScannableUndirected. I needed to change to "AdvertisingSet" and in the AdvertisingSetParameters set both isConnectable and isScannable to false to be able to send NonConnectableUndirected. Now the HoloLens recevies the advertisments from my Android device.