I am sending this from my BLE device:
BTLEserial.print ("one");
BTLEserial.print (",");
BTLEserial.print ("two");
So what I am sending is: "one, two" and i am now trying to get this value but with my current code I get 54
and 44
instead and I do not quite know why.
I use this plugin: https://github.com/xabre/xamarin-bluetooth-le (Plugin.BLE)
This is how I read the data:
var adapter = CrossBluetoothLE.Current.Adapter;
await adapter.ConnectToDeviceAsync(mydevice);
var service = await mydevice.GetServiceAsync(Guid.Parse("6e400001-b5a3-f393-e0a9-e50e24dcca9e"));
var services = await mydevice.GetServicesAsync();
var RXcharacteristics = await service.GetCharacteristicAsync(Guid.Parse("6e400003-b5a3-f393-e0a9-e50e24dcca9e"));
var characteristics = await service.GetCharacteristicsAsync();
int whatResult = 0;
string valueone;
string valuetwo;
RXcharacteristics.ValueUpdated += (sender, e) =>
{
var result = e.Characteristic.Value;
foreach (var items in result)
{
if (whatResult == 0)
{
valueone = Convert.ToString(items);
System.Diagnostics.Debug.Writeline(valueone);
whatResult++;
}
else {
valuetwo = Convert.ToString(items);
System.Diagnostics.Debug.Writeline(valuetwo);
whatResult = 0;
}
}
};
await RXcharacteristics.StartUpdatesAsync();
How come I cannot get the correct data from the result I am receiving? I also tried with var result = e.Characteristic.StringValue;
but with the same result.
I googled and came across a person with the same issue: https://github.com/xabre/xamarin-bluetooth-le/issues/88
He for example said this, which showcase that my device has CanUpdate
as true. And as I said above I succesfully get data from my code but I do not get the correct values.
The RXCharacteristic has CanWrite = false, CanRead = false, CanUpdate = true
If I use this app:
https://github.com/adafruit/Bluefruit_LE_Connect_v2
That is open source (coded with swift) I can succesfully get the correct value