1

How to check all incoming requests from paired BLE device to current device?

I think it possible with Events, maybe UWP have needle event, or i must implement custom event, but where is the right way?

Microsoft have explainations about GATT Server, i think it's not what i need, 'cause i don't need a server with services and characteristics, i need only check incoming request and parse passed data in my application.

2
  • 1
    What have you tried? How is the connection established? What are the services / characteristics exposed by the device? May 15, 2018 at 10:40
  • Look, two devices are connected and paired. One time, when i tried to check heart rate from second device, he perform request to first device (to application). Then i handle it and do some stuff but one time (when press the button). BUT, my question is to check incoming requests ALWAYS, maybe in other task, but catch it only when second device doing request (he can do request manually, without callback from first device.)
    – 4L3X
    May 15, 2018 at 10:56

1 Answer 1

0

I'm not found sure way for checking incoming requests, but i make some trick. Application can subscribe for notifications from device (in my case it's Mi Band 2) and receive some data from this device across ValueChanged. One time i call ValueChanged handler in App.xaml.cs after connecting and pairing device and this working on all application, i don't need call it again and again.

Here is App.xaml.cs part of code.

    protected async override void OnLaunched(LaunchActivatedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;
        MiBand2SDK.MiBand2 band = new MiBand2SDK.MiBand2();
        var page = typeof(Views.AuthPage);

        // Checking for device availability and current session
        if (_LocalSettings.Values["isAuthorized"] != null 
            && await band.ConnectAsync())
        {
            if (e.PreviousExecutionState == ApplicationExecutionState.NotRunning && await band.Auth.AuthenticateAsync())
                page = typeof(Views.MainPage);
            else if (band.Auth.IsAuthenticated())
                page = typeof(Views.MainPage);

            // Here we are, this notification handler of responses from the band.
            band.HeartRate.SetNotificationHandler();
        }
        else
        {
            System.Diagnostics.Debug.WriteLine("Not Authenticated...");
        }
       // other part of code...

Here is HeartRate.SetNotificationHandler() code:

    public async void SetNotificationHandler()
    {
        _heartRateMeasurementCharacteristic = await Gatt.GetCharacteristicByServiceUuid(HEART_RATE_SERVICE, HEART_RATE_MEASUREMENT_CHARACTERISTIC);

        Debug.WriteLine("Subscribe for HeartRate notifications from band...");
        if (await _heartRateMeasurementCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify) == GattCommunicationStatus.Success)
            // Just subscribe for notifications and set ValueChanged. It's all.
            _heartRateMeasurementCharacteristic.ValueChanged += HeartRateMeasurementCharacteristicValueChanged;
    }

Hope it helps someone...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.