adabru / BleWinrtDll

BLE for Unity 3d in Windows without UWP.
Do What The F*ck You Want To Public License
168 stars 52 forks source link

Hololens 2 unable to connect to Microbit #59

Closed nmitrak closed 7 months ago

nmitrak commented 7 months ago

Hi I am trying to connect Hololens 2 with a Microbit and read the Temperature sensor value of the Microbit. While this is a success when i run this on Unity Editor (many many thanks to adabru and marianylund for the effort) this doesn't comply when the application is deployed on the Hololens 2. Hololens finds the Microbit device but cannot connect after scanning it. After some examination of the problem it seems that it cannot retrieve the BLE profile of the micro:bit Error Message Could not establish connection to device with ID BluetoothLE#BluetoothLEf4:7b:09:80:e9:d5-d2:c7:fb:ef:ad:dd System.Exception: Connection failed: BleWinrtDll.cpp:117 Failed to connect to device at BLE.Connect(System.String deviceId, System.String serviceUuid, System.String[] characteristiccUuids) [0x00000] in

<000000000000000000000000000000000>:0 and a bunch of other messages Any suggestions? I look forward to your support. Kind regards
adabru commented 7 months ago

Would it be possible to compile and run the Microsoft sample on the Hololens 2?

nmitrak commented 7 months ago

After deploying the Microsoft sample it seems that Hololens 2 can discover the Microbit connect to a service and subscribe to a characteristic although the attribute isConnectable is false (1st pic)

20240107_231751_HoloLens 1 20240107_231826_HoloLens 2 20240107_232009_HoloLens 2

This was my main question: whether Hololens can pair with Microbit because Microsoft documentation stated that Hololens 2 can connect with devices that have a Gatt profile. What could be wrong and Hololens 2 cannot connect through the Unity project? Again thanks for your time.

adabru commented 7 months ago

In the Unity demo scene only devices with isConnectable set to true are shown: https://github.com/adabru/BleWinrtDll/blob/f2635b7b02432ea3006983657107f092c862171d/BleWinrtDll%20Unity/Assets/Scenes/Demo.cs#L67

You can try to comment out that part of the expression.

If you encounter further differences between the Microsoft sample and the Unity demo scene, you can compare the Microsoft code to BleWinrtDll/BleWinrtDll.cpp .

adabru commented 7 months ago

Oops, I overlooked that you already connected in your first post. You can also try to debug with DebugBle/Program.cs . You'd have to replace "CynteractGlove" with "BBC micro.bit [gotot]", "{f6f04ffa-9a61-11e9-a2a3-2a2ae2dbcce4}" with your serviceUuid, "{f6f07c3c-9a61-11e9-a2a3-2a2ae2dbcce4}", ... with your characteristicUuid and comment out the BLE.WritePackage statement.

nmitrak commented 7 months ago

Again thank you for your response. When i run DebugBle/Program.cs on the laptop everything is ok as you can see at the screenshot below. 2024-01-08 Is there a way to deploy this on Hololens 2? Thank you

adabru commented 7 months ago

Maybe it's possible to compile the Console Program for "ARM64" as well and run the .exe on the HoloLens? You somehow managed to run the Microsoft sample there as well, didn't you? :sweat_smile:

nmitrak commented 7 months ago

Maybe it's possible to compile the Console Program for "ARM64" as well and run the .exe on the HoloLens? You somehow managed to run the Microsoft sample there as well, didn't you? 😅

Yes you are absolutely right but now i don't have the option target Device that i had with the Microsoft sample in order to deploy the program to Hololens. Which file of Microsoft Sample is similar to BleWinrtDll/BleWinrtDll.cpp ?

adabru commented 7 months ago

This one: https://github.com/microsoft/Windows-universal-samples/blob/main/Samples/BluetoothLE/cppwinrt/Scenario2_Client.cpp

Or the equivalent C# version: https://github.com/microsoft/Windows-universal-samples/blob/main/Samples/BluetoothLE/cs/Scenario2_Client.xaml.cs

nmitrak commented 7 months ago

Hi

I managed to build your BleWinrtdll app for unity, deploy it succesfully on Hololens 2 and pair Hololens 2 succesfully with microbit by using the 2 compiled dlls from marianylund's application. 2024-01-10

Thank you very much again for you time, and congrats to you and marianylund for your work