Forum Xamarin.Android

Unable to write new data in BLE Characteristic

I'm using the Monkey.Robotics BLE library in my Xamarin.Android project.
I'm trying to connect to specific BLE device and change some specific Characteristic in it.
I can find and connect to this device. I'm also succeeded in discovering all services and characteristics in this device (including one that I need to write new data in it)
BUT I can't to write new data (0x01) in this characteristic.
See the code below:

MyChar.Write(new byte[] { 0x01 });

After this line I see that MyChar.Value is updated to be 1, but in the device this characteristic is NOT updated.
What I'm doing wrong?


  • GrahamMcKechnieGrahamMcKechnie AUMember ✭✭✭

    I'm not familiar with the library you are using, but it must have GattCallback class, so put a break point in the OnCharacteristicWrite override and check the value of the Characteristic and check if it has a value of 1

    Are you sure that the particular characteristic has a write property? You could check that by downloading an app called BLE Scanner, from BluePixel technology on Google play. There are others apps that do the same thing, but I can't recall their names. Connect to your device, find the service and check the properties of the particular characteristic.

    What device are you connecting to? What is meant to happen when you right the value of 1 to that characteristic?

  • YuraGagarinYuraGagarin USMember

    Hi again
    After some debugging I get the real problem:
    After connecting to my BLE device and discovering all services and characteristics I try to write new values in 2 different characteristics in the same Service.
    The first "write" is succeeded BUT the second one don't.
    I tried to write different values in the same characteristic one after another with some time delay BUT again I get the same result - first "write" is succeeded BUT the second one don't.
    I don't have BLE sniffer so I don't know if I'm actually send the second "write" but the code is the same as for first one.
    I use the LGE Nexus5 phone.
    What can be the problem??

  • GrahamMcKechnieGrahamMcKechnie AUMember ✭✭✭

    How do you check your write succeeded?

    You should be checking the value of the characteristic in OnCharacteristicWrite or OnCharacteristicChanged in the GattCallback. Easy enough to find out which, but adding a break point to each. I don't understand why you would write to the same characteristic twice, if all you are doing is writing a single byte with the value of 1. Are you just setting a value to true? You don't say what the the device is so I'm only guessing.

    Do you have the documentation of the BLE device? If so please describe what the device is meant to do and what the function is of the two characteristics, that you refer to. There is no need for any delays between writes. When it is written, you check it it has been in the callback and then proceed with what ever is required with the other characteristic.

    BLE Scanner is not a sniffer. It connects to your device, displays all the services of the device, the characteristics of each service, and the descriptors of each characteristic, if the characteristic has descriptors. Just download it from Google Play.

    Could the problem be in the Monkey lib? Why don't you ditch the library and write your own code to at least eliminate the lib.

    If your phone supports BLE then your phone isn't the problem. If an Android device doesn't support BLE, then you wouldn't be able to scan for devices, which obviously you can.

  • YuraGagarinYuraGagarin USMember

    Here is some explanations about my project
    This is my first project in Xamarin. I need to develop some simple application in Xamarin Android that connects by BLE to specific BLE device and write some new data in several Characteristics. The BLE device is working well and I can connect to it and read and write from it using different applications on PC or smartphone.
    After some reading I understand that majority of BLE projects on Xamarin using Monkey.Robotics BLE library so I use it too.
    If you can point me to other BLE library with examples it will be great.
    May be you know some good example project that use pure Android.Bluetooth/Android.Bluetooth.LE libraries it will be awesome.


  • GrahamMcKechnieGrahamMcKechnie AUMember ✭✭✭

    Well I can't help you out with a specific library because I don't use one. Not knowing what your device is, I'm not sure if this helps or not, but I did today in an earlier message start a new thread re a BLE tutorial. Take a look it may help you.

  • LiorTLiorT ILMember

    Hi Graham -

    If you do not use a specific library. Can you please recommend a better way to work with BLE?
    Can you direct to good and comprehensive example for building a BLE app? or an in-depth instructions?


  • GrahamMcKechnieGrahamMcKechnie AUMember ✭✭✭

    Hi Lior,

    Did you not read my last comment? Look for the thread Bluetooth LE Texas Instruments SensorTag Tutorial it contains a link to a sample

  • BrightLeeBrightLee KRMember ✭✭✭
    edited March 2017

    @YuraGagarin @LiorT

    Hi, Why are you still using Monkey?
    It's way outdated library.
    I recommand you to use xabre's ble plugin if it's possible.

Sign In or Register to comment.