Giter Site home page Giter Site logo

kirk-quinbar / heartratele Goto Github PK

View Code? Open in Web Editor NEW
24.0 7.0 9.0 3.36 MB

C#/WPF sample for calling WinRT apis to communicate with Bluetooth LE heart rate devices

License: MIT License

C# 100.00%
c-sharp bluetooth-low-energy heart-rate wpf uwp winrt

heartratele's People

Contributors

kirk-quinbar avatar kquinbar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

heartratele's Issues

Check if bluetooth support available

Your code works perfect in windows update 1709. I was able to create a WinForms application receiving measurements from a Polar H7.
I was looking for a method to check weather bluetooth support is available on the machine, but did not find any. Somewhere in the internet I found a code snippet like this:

    public static async Task<bool> BluetoothIsSupportedAsync()
    {
        var radios = await Radio.GetRadiosAsync();
        var bluetoothRadio = radios.FirstOrDefault(radio => radio.Kind == RadioKind.Bluetooth);
        return bluetoothRadio != null;
    }

But this isn't working. The GetRadiosAsync function is returning a __ComObject which cannot be evaluated.
Do you have any idea how to check if bluetooth is supported, bluetooth is enabled, bluetooth le is available.... ?
Brgds
Marcel

Windows 8.1 Support

Hi, Will this app work with Windows 8.1 for WPF? I installed VS 2015 on a Windows 8.1 machine and I am missing several references in the project. If I add the Windows 10 packages will this still function correctly on Windows 8.1?

1>------ Build started: Project: HeartRateLE.Bluetooth, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows.Foundation.FoundationContract". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows.Foundation.UniversalApiContract". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(8,15,8,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(9,15,9,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(10,15,10,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(11,15,11,23): error CS0234: The type or namespace name 'Security' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\PairingHelper.cs(6,15,6,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAEM\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\PairingHelper.cs(7,15,7,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(2,15,2,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\DeviceSelectorInfo.cs(6,15,6,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(6,15,6,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(7,15,7,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(8,15,8,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(6,15,6,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(7,15,7,22): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(8,15,8,23): error CS0234: The type or namespace name 'Security' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(9,15,9,22): error CS0234: The type or namespace name 'Storage' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(263,52,263,69): error CS0246: The type or namespace name 'BluetoothLEDevice' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(273,44,273,62): error CS0246: The type or namespace name 'GattCharacteristic' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(273,71,273,96): error CS0246: The type or namespace name 'GattValueChangedEventArgs' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\PairingHelper.cs(37,53,37,83): error CS0246: The type or namespace name 'DeviceInformationCustomPairing' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\PairingHelper.cs(37,92,37,123): error CS0246: The type or namespace name 'DevicePairingRequestedEventArgs' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(90,30,90,43): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(95,43,95,56): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(124,34,124,47): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(124,56,124,73): error CS0246: The type or namespace name 'DeviceInformation' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(150,36,150,49): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(150,58,150,81): error CS0246: The type or namespace name 'DeviceInformationUpdate' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(172,36,172,49): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(172,58,172,81): error CS0246: The type or namespace name 'DeviceInformationUpdate' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Utilities.cs(71,48,71,55): error CS0246: The type or namespace name 'IBuffer' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(17,17,17,34): error CS0246: The type or namespace name 'BluetoothLEDevice' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\ENAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartDeviceWatcher.cs(25,17,25,30): error CS0246: The type or namespace name 'DeviceWatcher' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\HeartRateMonitor.cs(22,17,22,35): error CS0246: The type or namespace name 'GattCharacteristic' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(16,35,16,52): error CS0246: The type or namespace name 'GattDeviceService' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(22,35,22,53): error CS0246: The type or namespace name 'GattCharacteristic' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(11,16,11,34): error CS0246: The type or namespace name 'GattCharacteristic' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(12,16,12,30): error CS0246: The type or namespace name 'GattDescriptor' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\BluetoothAttribute.cs(14,16,14,33): error CS0246: The type or namespace name 'GattDeviceService' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\ENAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\DeviceSelectorInfo.cs(24,16,24,27): error CS0246: The type or namespace name 'DeviceClass' could not be found (are you missing a using directive or an assembly reference?)
1>C:\Users\NAME\Desktop\HeartRateLE-master\HeartRateLE-master\HeartRateLE.Bluetooth\Schema\DeviceSelectorInfo.cs(30,16,30,37): error CS0246: The type or namespace name 'DeviceInformationKind' could not be found (are you missing a using directive or an assembly reference?)

Getting System.UnauthorizedAccessException when getting characteristics

Getting System.UnauthorizedAccessException, Access is Denied (E_ACCESSDENIED) error being thrown within the bluetooth library. Looks to be as available devices are enumerated and gattdeviceservice.getcharacteristics may be the culprit method. this too may be directly tied to the Windows Creator update the microsoft released

Fix iscompatible function to not fail if exception

private async Task IsDeviceCompatible(string deviceId)
{
var compatibleDevice = true;
try
{
var device = await BluetoothLEDevice.FromIdAsync(deviceId);

            //if filters were passed, check if the device name contains one of the names in the list
            if (_filters != null)
            {
                compatibleDevice = _filters.Any(a => device.Name.CaseInsensitiveContains(a));
            }

            //filter out any devices that are not heart rate devices. with the current bluetooth apis, this will
            //only occur if the device is paired. the windows creator update is supposed to allow for checking for this
            //on unpaired devices, but a recent build completely broke bluetooth le support, so this is the best
            //that can be done for now.
            if (device.GattServices.Any() && compatibleDevice)
            {
                bool matches = true;
                foreach (var requiredService in RequiredServices)
                {
                    matches = CheckForCompatibility(device, requiredService.ToGuid());
                    if (!matches)
                        break;
                }
                compatibleDevice = matches;
            }
        }
        catch
        {

            compatibleDevice = false;
        }


        return compatibleDevice;
    }

Cannot pair and connect to my Heart rate device?

Hello,
First i would like to thank you a lot for sharing with us this example in such random subject, we really appreciate that.

Now i have a question, is this plugin suppose to work with all types of Heart rate devices?
I am trying to test the example with different devices, i am able to find all my devices in scan result always but when it comes to pairing, i can pair my smart watch but not my other heart rate device that i am suppose the receive data from it. I always get failed as result of pairing request.

Some informations about the device:
-Activation time 60sec
-BLE version 4.x

The Windows version is: Windows 10 Pro 1803

I really appreciate if guide me through the reasons of not being able to pair to my device.

Value changed events not firing but ConnectionStatusChanged is

This may be related to the latest Windows Creator update per Bruce

http://www.drivethelife.com/windows-10/bluetooth-issue-windows-10-creators-update.html

https://blogs.windows.com/buildingapps/2017/01/13/new-bluetooth-features-in-creators-update-gatt-server-bluetooth-le/

For various Bluetooth issues, Microsoft recommends running the new Bluetooth Troubleshooter, a new troubleshooting tool you can find on the Settings page. Go to Settings > Update & security >Find and fix other problems > Troubleshoot.

https://answers.microsoft.com/en-us/windows/forum/windows_10-hardware/bluetooth-not-working-properly-after-creators/02296fc8-f7db-4597-94ea-3fd85dc5edfc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.