locked
.Net Core Difference Windows and IoT Core RRS feed

  • Question

  • Hello together,

    this is my first question in a forum and i feel really bad about it. 
    Normally i get any information by google, but this time its tough.

    Before starting my question i want to share my goals, which are more important than the error:
    - App in C#
    - Running on Raspberry PI (Version/Platform is irrelevant)
    - Using Bluetooth (Pairing without user interaction)

    My Problem:
    I tried developing a UWP-Background-App on IoT Core. I struggled with the problem on pairing, that userinteraction in necessary.
    Please have a look at this thread: https://social.microsoft.com/Forums/en-US/cb2722f2-2e62-4df3-9141-0c6eba7c94be/rfcomm-with-iotcore-can-custom-bluetooth-pairing-be-performed-by-an-iot-core-uwp-app-without?forum=WindowsIoT

    Than i tried developing a Core-App, which runs under Windows without user interaction. This is the log:

    03:59:39: Started
    03:59:40: Info: Started Discovery
    03:59:40: Disconvering...
    03:59:40: Info: Found BC_IR_DETECTOR_3
    03:59:40: Info: Try connecting BC_IR_DETECTOR_3
    03:59:40: Info: Start connecting...
    03:59:40: Info: Connecting...
    03:59:40: Info: Found HTC BS EEEC2C
    03:59:40: Info: Found
    03:59:40: Info: Found iConTank
    03:59:40: Info: Found iConTank
    03:59:40: Info: Device changed Bluetooth#Bluetooth18:1d:ea:8c:bd:28-98:d3:31:f7:43:0d
    03:59:44: Info: Conntected
    03:59:44: Found -> BC_IR_DETECTOR_3 - Connected: True (0 ms)
    03:59:45: Updated -> BC_IR_DETECTOR_3 - Connected: True (66 ms)
    03:59:46: Updated -> BC_IR_DETECTOR_3 - Connected: True (71 ms)
    03:59:47: Updated -> BC_IR_DETECTOR_3 - Connected: True (58 ms)
    03:59:48: Updated -> BC_IR_DETECTOR_3 - Connected: True (67 ms)

    So it is doing what i want ...

    Using the exact same software on windows 10 iot core causes a crash/or unexpected behavior:

    6:47:21 PM: Started
    6:47:21 PM: Info: Started Discovery
    6:47:21 PM: Disconvering...
    6:47:21 PM: Info: Found
    6:47:21 PM: Info: Found HEIMDALL
    6:47:21 PM: Info: Found BC_IR_DETECTOR_3
    6:47:21 PM: Info: Try connecting BC_IR_DETECTOR_3
    6:47:21 PM: Info: Start connecting...
    6:47:21 PM: Info: Pairing...
    [192.168.0.49]: PS C:\Data\Users\Administrator\Documents\publish>
    Does anyone have an advice, what i should do next? This problem is a showstopper for my project.

    Thanks in advance!
    Monday, June 22, 2020 2:03 AM

Answers

  • Hello together,

    i've found the solution.

    I was testing the .Net Core Console App via Remote Powershell.

    In Main-Program there was a Console.Readline() at the End to continue async tasks until user hits a button (would never happen, but prevented the app from exiting).

    If i replace it with a while sleep loop. It works ...

    So there must be any problem with Remote Powershell getting userinputs or some sort of timeout.

    Now i have a headless bluetooth pairing, without user interaction!

    Tuesday, June 30, 2020 10:39 AM

All replies

  • Hello Christian Edel,

    Which version of Windows IoT Core were you using? If possible, could you please share the code snippet. In addition, please clarify that your application is implemented by .Net Core or  an 'headless' application(Developing Background Applications).

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 23, 2020 7:00 AM
  • Hello,

    i tried UWP-App (With UI), .Net Core 3.1 Console App, IBackgroundTask (So Background App).

    As u see from the log above there should be anywhere "Pairing requested".

    Im using version 17763

    My Code-snippet:

    ErrorHandler.RaiseInformation(this, "Start connecting...");
    
    bool paired = _bluetoothDevice.Pairing.IsPaired;
    bool connected = false;
    
    if (!paired)
    {
         ErrorHandler.RaiseInformation(this, "Pairing...");
    
         DeviceInformationCustomPairing customPairing = _bluetoothDevice.Pairing.Custom;
         customPairing.PairingRequested += CustomPairing_PairingRequested;
         var pairingResult = await customPairing.PairAsync(DevicePairingKinds.ConfirmOnly | DevicePairingKinds.DisplayPin | DevicePairingKinds.ProvidePin | DevicePairingKinds.ConfirmPinMatch, DevicePairingProtectionLevel.Default);
         paired = pairingResult.Status == DevicePairingResultStatus.AlreadyPaired ||
                  pairingResult.Status == DevicePairingResultStatus.Paired;
    
         ErrorHandler.RaiseInformation(this, "Pairingstatus " + pairingResult.Status.ToString());
    }
    
    if (paired)
    {
         ErrorHandler.RaiseInformation(this, "Connecting...");
         connected = await ConnectHandler();
    }
    
    if (connected)
         ErrorHandler.RaiseInformation(this, "Conntected");
    else
         ErrorHandler.RaiseInformation(this, "Connect Failed");

    and that is the requesthandler

    private void CustomPairing_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
    {
        ErrorHandler.RaiseInformation(this, "Pairing requested " + args.PairingKind);
    
        switch (args.PairingKind)
        {
            case DevicePairingKinds.ConfirmOnly:
                args.Accept();
                break;
            case DevicePairingKinds.DisplayPin:
                args.Accept();
                break;
            case DevicePairingKinds.ProvidePin:
                args.Accept("####");
                break;
            case DevicePairingKinds.ConfirmPinMatch:
                args.Accept();
                break;
            default:
                break;
        }
    }

    Wednesday, June 24, 2020 5:52 PM
  • Hello Christian Edel,

    Was the above code in .net core app or background app? I tried to run the above code in headless app on Windows IoT Core. The pairing always fails but without crash.Did you mean the cuased crash is app or Windows IoT Core? Basically, there are no differences between on Windows and IoT(Cross-Platform IoT Programming with .NET Core 3.0) about .net core.

    Best Regards,

    Michael


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 26, 2020 5:35 AM
  • Hi Michael,

    with all project types. The behaviour is different.

    In UWP and Background App the Request Hander just doesn't get called.

    in .NET Core the app or thread dies.

    Unfortunately i can't remote debug ... so i have to look at my own logging. 

    As you see what i wrote in my initial post, calling the app via powershell brings me back to powershell input, which tells me, that the app crashes. 

    On Windows 10 (18363.900) the app paires the BT-Adapter and starts receiving messages (Ping Loopback, Own implementation).

    So there must be any difference ... 

    To be honest i don't care about platform/framework. Only requirements are:
    - Pairing without user interaction
    - Able to run on IoT-Core (RaspPI, which Raspi doesn't matter either)

    Thanks a lot, this "bug" or "feature" is driving me crazy.

    Saturday, June 27, 2020 11:48 PM
  • If you want to, i can share the project with you (please in confidence) or (since the project contains a lot a projects) i can show you via TeamViewer or similar.

    Of course i would share the solution in here.

    Thank you very much!


    Tuesday, June 30, 2020 12:06 AM
  • Hello together,

    i've found the solution.

    I was testing the .Net Core Console App via Remote Powershell.

    In Main-Program there was a Console.Readline() at the End to continue async tasks until user hits a button (would never happen, but prevented the app from exiting).

    If i replace it with a while sleep loop. It works ...

    So there must be any problem with Remote Powershell getting userinputs or some sort of timeout.

    Now i have a headless bluetooth pairing, without user interaction!

    Tuesday, June 30, 2020 10:39 AM