I was wondering, if there is a problem with the UWP Bluetooth API and Indicate. If I understand the documentation correctly UWP will handle the Acknowledgment of a received Indicate package. But for some reason, the sample code works for notifys but not for indicates. I am trying this with a Myo Wristband. I can receive notifications via notify characteristics but not via the indicates one. Unfortunately I have to use indicate.
I changed the sample code a little bit to this, but its not working:
GattCommunicationStatus status = await selectedCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(
GattClientCharacteristicConfigurationDescriptorValue.Indicate);
if(status == GattCommunicationStatus.Success)
{
// Server has been informed of clients interest.
}
and the Handler stays the same:
characteristic.ValueChanged += Characteristic_ValueChanged;
// ...
void Characteristic_ValueChanged(GattCharacteristic sender,
GattValueChangedEventArgs args)
{
// An Indicate or Notify reported that the value has changed.
var reader = DataReader.FromBuffer(args.CharacteristicValue)
// Parse the data however required.
}
Any ideas what I am doing wrong? The device is connected and correctly programed, it sends the notifications.
Thanks in Advance for any help
Marcel
I found the answer to my question. It was not a problem of UWP, but of the Myo. The code above works for Indicate, just change the notify to indicate and your good to go.
For everyone else in the future. I was making a mistake with the command bytes. I misunderstood the Bluetooth Header file and thought that the payload equals the command, but it not like that. So after each command byte you have to send the amount bytes, you give as "argument". This is the payload. Its said in the header, but I somehow missed it.
So for example, to set the myo to EMG_none, IMU_send_all, Classifier_Enabled you have to send this byte to the CommandCharacteristic:
01 03 00 03 01
where the first 01 is the set_mode, the first 03 the payload (3 "Arguments"), the 00 the EMG_none, the second 03 the IMU_send_all, the last 01 the Classifier_enabled.
Wished they had made an example command on their tutorial :-)
The full header can be found here: https://github.com/thalmiclabs/myo-bluetooth/blob/master/myohw.h
and a short explanation here: http://developerblog.myo.com/myo-bluetooth-spec-released/
Hope that will help someone.