This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Does nrf toolbox (android) work on nrf52 related SD, e.g. S140?

Hello everybody!

Feel free to read this question for more background information:

devzone.nordicsemi.com/.../

I'll give everyone reading this a quick bulletin run down as to what happened to save time:

  • Migrating from nrf51 S110 to nrf52 S120
  • ble_hvx() function on my nrf52840 returns "0x00000008" "INVALID STATE" error.
  • Most likely the cccd handle wasn't set by my android app
  • But it worked flawlessly back in nrf51 S110
  • User Endnode here told me that it's very likely that the old android API function (not to be mistaken with the nrf51 MCU function I mentioned above, the successful establishment of the communication between android device and MCU requires many functions on both sides) setcharacteristicnotification, which use "WRITE" method on the GATT instead of "REQUEST" method, fails to trigger the proper set cccd handle operation, and is likely ignored altogether by the latest S140 SD.

So, I went on trying to find the relevant function, but couldn't. I'm here thinking, shouldn't nrf toolbox be working with S140 on Nrf52 series? If that's the case, I'll just use whatever function they are using from the android API, and mission accomplished?

I'm trying to git the APP source code to local, but at this point, I don't know if the tool box work at all, if it does, then it'll just be monkey see monkey do kind of deal, if not, I'm not going to spend my time on it.

Also, if you are familiar with this, feel free to tell me what function the toolbox use to set the cccd handle.

Cheers.

  • Hello @Aleksander, how do you mean by:

    write something to the char before you enable notifications/indications on it,

    ? Write something to what char?

    This is what I believe you should do to enable CCCD in an android program:

    1. call BluetoothGatt.setCharacteristicNotification on the right characteristic.
    2. Write 0x0001, in android, a byte[] of 0x01, 0x00 to the corresponding descriptor of the characteristic in step 1.
    3. No step 3, it's done!

    The problem is #2, I believe you should write 0x0001 using some sort of "request" instead of "write", but sadly I don't know how to do that, there are all sorts of "write" in android API it seems, but nothing about "request".

    And can you please help me find the right API/property setter??

    It'll be greatly appreciated.

  • On Android it's called WRITE_DEFAULT. If the characteristic you want to enable notifications for has Write_no_response property, and no Write property, then the default write type for it may have been set to Write_without_response. This is correct, but due to a bug in Android 4.4-5.1 the same type will be used for writing to its descriptors, which is not correct. Before your step 2. you have to set characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_DEFAULT), and then write 0x0001 to the cccd.

  • @Aleksander, thank you, I'll look right into it, so it has something to do with the step 1 eh? I never thought you should work on the function "BluetoothGatt.setCharacteristicNotification" itself. I didn't even know BluetoothGatt.setCharacteristicNotification has its own writing properties.

    Will get back later!

  • No, it's about step 2 only. Step one just adds your BluetoothGatt object to notification listeners in the system. Had the notifications were enabled before you connected in your app to this device it's enough to call only step 1. It's an information for the system that you want to receive whatever comes to this characteristic.

    Step 2 enables notification on the remote device by sending some data (0x0001). This write to the ccc descriptor should be done with Write Request type, but incorrectly may be written without response. Older SDa were accepting this out-of-spec method, the new one isn't.

  • Before your step 2. you have to set characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_DEFAULT), and then write 0x0001 to the cccd.

    Hello, I'm sorry that I misunderstood your post, but I've tried the characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT); it does not work.

    My BLE GATT handler doesn't even respond after using the "WRITE_TYPE_DEFAULT" property, moreover, there is no "WRITE_DEFAULT" property at all. "WRITE_TYPE_DEFAULT" is the closest I could find.

    Something is seriously wrong here?

Related