Reading values from TI BLE CC2540 on android fails with status = 10 [duplicate]

旧城冷巷雨未停 提交于 2019-12-11 14:45:32

问题


I have a device with CC2540 chip that I try to connect and read / write data from Android.

The device is discovered, I am able to connect, but when I try to send read command I get status = 10 at:

public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)

I used "BLE sensor tag" source code and changed UUIDs according to mine - I get the same result

I used "BLE device monitor" app from Google Play - I get the same result (screen shot attached)

My questions are:

  1. What does "status = 10" stands for?

  2. Where does it comes from? The chip? Android?

  3. How can debug it?

I have an iPhone device and it works great...


回答1:


What does "status = 10" stands for?

It can be anything really, since you can't access to BLE Device Monitor's source. You can find generic GATT profile status codes here(BluetoothGatt)

Do you see the same error code when you run TI's "BleSensorTag" source example?

Where does it comes from? The chip? Android? How can debug it?

That's what Android's BluetoothGattCallback() function interprets from the chip accessing it through BluetoothAdapter.

I recommend focusing on "BleSensorTag" source code; For the status code find

private BluetoothGattCallback mGattCallbacks = new BluetoothGattCallback() 

in "BluetoothLeService.java" about line #82. That's where you get the status code and those overridden callbacks then registered to BluetoothDevice object's connectGatt() method.

mBluetoothGatt = device.connectGatt(this, false, mGattCallbacks)

I would also make sure that my BLE packets are in the correct form using TI's sniffer if possible. If not you may as well debug what's coming out of BluetoothAdapter.LeScanCallback

Again in the "BleSensorTag" find public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) method in MainActivity.java. And change;

public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) {
      runOnUiThread(new Runnable() {
        public void run() {
            // Filter devices

to:

public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) {

      final byte[] scanRecordStream = scanRecord;

      runOnUiThread(new Runnable() {
        public void run() {
            // Filter devices

            Log.i(TAG, "scanRecord:" + Conversion.BytetohexString(scanRecordStream, scanRecordStream.length));

rest is the same and you should see your byte stream in the logcat.

[edit] Here is the LE Generic Packet Structure according to Core Bluetooth Spec V4.0

The following is an example BLE packet byte structure, I added it as an example in case you might want to compare your packet's length when you log it on the console and have something to use as a reference.

A BLE advertising packet could be expected to have the generic form:

02 01 06 1A FF 4C 00 02 15: iBeacon prefix (fixed)
B9 40 7F 30 F5 F8 46 6E AF F9 25 55 6B 57 FE 6D: proximity UUID (here: Estimote’s fixed UUID)
00 49: major
00 0A: minor
C5: 2’s complement of measured TX power

Happy debugging.



来源:https://stackoverflow.com/questions/23977783/reading-values-from-ti-ble-cc2540-on-android-fails-with-status-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!