I am using the Windows-Universal-Samples BluetoothLE sample as a starting place to connect to a Polar heartrate device, but ultimately i want the functionality in a desktop application. Using the WIndows 10 SDK (10.0.15063.0), I created a standalone class library to provide the functionality of connecting to this Polar device and i copied over parts of the sample code for the bluetoothLE Scenario2_Client.xaml.cs. I can get everything to work in the class library except no matter what ive tried i cannot get the ValueChanged event to fire when subscribed to the GattCharacteristic for the HeartRateMeasurement characteristic of the HeartRate service. if i run the bluetoothLE sample code, i can connect to the Polar device and can select that service and characteristic and the ValueChanged events fires as expected.
Is it possible the Windows 10 SDK 10.0.15063.0 has issues with the bluetooth api? prior to the release of the creator's edition, i could get the valuechanged event to fire, but that was using an older version of the bluetooth api stuff and most of it stopped working once the windows creator edition was released, so i am having to rewrite it.
I suppose its possible that there is something wrong with my code, but i did copy a lot of the basic connection and subscribing to the event from the bluetoothle sample. the only difference is that I am using a WPF app for the UI, but the bluetooth code should be very similar
this is my rewrite code. the HeartRateMonitor class is the basic implementation that connects to the Polar device, sets up the heartrate service and characteristic and subscribes to event, plus start the notify.
https://github.com/kirk-quinbar/HeartRateLE/tree/rewrite
been playing around with this for a week and so far cannot get the ValueChanged of the characteristic to fire as expected. driving me nuts. any thoughts on things to check for, or anyone is welcome to check out my code above for suggestions.
Related
I'm developing a Bluetooth app using UWP framework under Visual Studio 2017. Everything is going well thanks to Microsoft Example (C# SDK Example BluetoothLE well written).
During my fourth day of development, the API BluetoothLEDevice.FromIdAsync in the line:
bluetoothLeDevice = await
BluetoothLEDevice.FromIdAsync(bleDeviceToConnect.Id);
Is no longer working, neither in my app, neither in the original sample from Microsoft I'm using as example (I don't touch anything on it).
I don't understand as I changed nothing (in my project properties, neither any Windows update on my computer). When I call the function, it just never return.
I tried my Bluetooth object used with some smartphone app, and my hardware is working well.
The call is made in a try but no exception is catch, the function just never return (and I wait some time, I don't even have a timeout).
Have you seen this? Any input on how to solve it?
I'm totaly stuck and can't go ahead as I can't connect at all any object now...
If your code and the example code are having the same problem, the only reasons can be that your device is not available.
It is out of reach or even switched off or already connected.
It can also be that if you are using the deviceManager or deviceWatcher, your OS is providing stale information.
For BluetoothLE the windows deviceManager and watcher are nothing but trouble.
Windows sometimes keeps the pairing information and connection status, even if the device is out of reach or switched off.
Many times you have to remove and and re-add your device in settings to make it available again or a restart is needed.
To save you from all these troubles, I advise you to use the advertisementWatcher.
If your device is found by the advertisementWatcher you know it is in reach and connectable, and there is no need to add your BLE-device in settings.
If needed I can provide a simple example.
This may happen because of COM security (as you may know UWPAPI based on WinRTYY which works above COM). This should help.
Hello All and thank you for your help on this.
I got a shot on an other computer and it works just fine.
I double check this morning and found out that even Widnows can't connect to anything over Bluetooth (I tried with the Bluetooth Speaker I'm usually using).
It was a Driver issue, I don't know how it happens, but my computer Driver just stop working, and I add to reinstall it.
So I've had a look around and I cant seem to find an answer anywhere so here goes. Is it possible with the MS Band SDK to run a function within my app when the user taps a button?
Currently (at the time of writing) there is no way for the user to directly interact with a tile-app and thus pass a response to the application installed on the phone*
Your options are (as I see it):
To use the sensors to define 'gestures'**
Guide the user to use Cortana to provide speech commands ***
*This might change, but due to the very little storage capacity on the band if this was added I would assume only very basic interaction such as yes/no/cancel dialogos etc. and simpler responses using the keyboard when/if it becomes available for third party tiles.
**There is currently a bug with background work so you might have to prevent the lock screen from locking while receiving and interpreting sensor data on the phone which will impact the battery on the phone. This is expected to be fixed soon.
*** Speech commands are well supported on Windows Phone but I'm unsure how well supported they are on iOS and Android
I having problems finding documentation or examples regarding the proper way to use the Accelerometer to trigger a Shake event. Seems like it should be easy, but all the examples are 8.0 which apparently are using Microsoft.Devices.Sensors;
Apparently you are supposed to use using Windows.Devices.Sensors; which you would think are the same, but things like Start() and Stop methods no longer exist. I was trying to use a Microsoft AccelerometerHelper class from Microsoft and it also uses the older namespace. The Shaken event in the Accelerometer class is only triggered on the tablets and not phones according to:
MSDN : here
Windows Phone 8: The accelerometer sensor does not raise the Shaken
event on the Windows Phone 8 platform. If you add an event handler for
the Shaken event in your Windows Phone 8 app, no error is raised, but
the code in the event handler won’t run.
The last resort or another option if you can't port the code to WP 8.1 Runtime is to switch the project to Windows Phone 8 Silverlight or even 8.1 Silverlight, all code work perfectly, I've worked with AccelerometerHelper class before and face the same problem.
I am developing a WinForms C# application, that needs to know when the computer is not "idle", that is, that a user is actively using it. I can detect keyboard and mouse activity in both the standard desktop and Metro (I think thats what they call it). I can also detect touchscreen activity in the standard desktop - these events are detected as mouse events.
However, using the touchscreen in Metro, none of these events are raised. I have tried this project: http://globalmousekeyhook.codeplex.com/ as well as writing code to hook into the Windows SetWindowsHookEx API with no luck.
I spent some time investigating the WinEvents API too, but can't find anything there that will help.
Anybody know if this can be done? And how?
There happens to be a nice function for that but unfortunately it is C++, so you'll have to P/Invoke it.
I have developed a music player app for Windows Phone 7.5 and Windows Phone 8. Now I want to listen to the music with various bluetooth devices. I can connect it to my phone and listen to music, so that's working just fine. But it acts weird in certain scenarios. If the music is paused it will resume on the speakers if I disconnect the bluetooth. I can see in my log that it receives a user action to UserAction.SEEK to the position it was when I turned off bluetooth. At this point, the player.Position variable has somehow gotten to be 0, so it goes to 0 and back to where I was. And I don't do anything that would cause that action.
What I am asking: Is there a way to take over control or to get any control in the AudioPlaybackAgent that I use of what happens when I do something with my bluetooth devices. Is there any event that occurs, or is all this handled by the OS? If so, why does my application behave differently than the stock app? Also, why am I receiving a UserAction.SEEK when I turn of my bluetooth device?
If my question is unclear, please don`t hesitate to ask!
This is a known issue with the platform, but is fixed in WP8 GDR2. You can workaround the issue by detecting an OnUserAction sequence of Pause Seek Play. Once detected, you can pause on the next call to OnPlayerStateChanged. A few things to be aware of:
Consecutive calls to OnUserAction aren't guaranteed to be called on the same instance of AudioPlayer, so any state should be stored in static state.
The track will play from the speaker for a brief moment, so you might want to set the volume to 0 (after making note of it's previous value, of course)
I've posted a Gist to GitHub with a full implementation. Example usage and a more detailed rundown of the problem is available on my blog.