从TI BLE CC2540 Android上的读数值失败,状态= 10 [英] Reading values from TI BLE CC2540 on android fails with status = 10

查看:1309
本文介绍了从TI BLE CC2540 Android上的读数值失败,状态= 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有CC2540芯片的设备,我尝试从Android的连接和读/写数据。

该设备被发现,我能够连接起来,但是当我尝试发送读命令,我会在状态= 10:

 公共无效onCharacteristicRead(GATT BluetoothGatt,BluetoothGattCharacteristic特征,诠释状态)

我用BLE传感器标签源$ C ​​$ c和改变的UUID根据我的 - 我得到同样的结果。

我用BLE装置监控从谷歌Play应用程式 - 我得到相同的结果(屏幕截图附后)

我的问题是:


  1. 什么是状态= 10代表?


  2. 它在哪里从何而来?该芯片? Android的?


  3. 如何调试呢?


我有一个iPhone的设备,它的伟大工程......


解决方案

  

什么是状态= 10代表?


它可以是任何真正的,因为你不能访问BLE设备监视器的来源。你可以在这里找到通用GATT轮廓状态codeS (BluetoothGatt)

你看到了同样的错误code当您运行TI的BleSensorTag源例子吗?


  

它在哪里从何而来?该芯片? Android的?
  如何调试呢?


这就是Android的 BluetoothGattCallback()函数间$ P $点从芯片访问它通过 BluetoothAdapter

我建议围绕BleSensorTag来源$ C ​​$ C;
对于状态code找到

 私人BluetoothGattCallback mGattCallbacks =新BluetoothGattCallback()

在BluetoothLeService.java关于线#82。这就是你得到的状态code和那些覆盖回调再注册到 BluetoothDevice类对象的<一个href=\"https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#connectGatt%28android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback%29\"相对=nofollow> connectGatt()方法

  mBluetoothGatt = device.connectGatt(这一点,假的,mGattCallbacks)

我也想确保我的BLE包以正确的形式采用TI 嗅探器< /一>如果可能的话。如果没有,你不妨调试什么是未来出<一个href=\"https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback.html\"相对=nofollow> BluetoothAdapter.LeScanCallback

再在BleSensorTag中找到公共无效onLeScan(最终BluetoothDevice类设备,最终诠释RSSI,字节[] scanRecord)方法MainActivity.java。而改变;

 公共无效onLeScan(最终BluetoothDevice类设备,最终诠释RSSI,字节[] scanRecord){
      runOnUiThread(新的Runnable(){
        公共无效的run(){
            //过滤装置

 公共无效onLeScan(最终BluetoothDevice类设备,最终诠释RSSI,字节[] scanRecord){      最后一个字节[] = scanRecordStream scanRecord;      runOnUiThread(新的Runnable(){
        公共无效的run(){
            //过滤装置            Log.i(TAG,scanRecord:+ Conversion.BytetohexString(scanRecordStream,scanRecordStream.length));

休息是相同的,你应该看到在logcat中的字节流。


下面是在 LE通用数据包结构根据蓝牙核心规格4.0版

下面是一个例子BLE包字节的结构,我增加一条,作为的情况下,您可能希望在登录时在控制台上,并有一些作为参考,用来比较的数据包的长度一个例子。

一个BLE广告包可以预期有通用的形式:

  02 01 06 1A FF 4C 00 02 15:iBeacon显示preFIX(固定)
B9 40 7F 30 F5 F8 46 6E AF F9 25 55 57 6B 6D FE:接近UUID(此处Estimote的固定UUID)
00 49:重大
00 0A:未成年人
C5:2的测量发射功率的补

快乐调试。

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...

解决方案

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.

这篇关于从TI BLE CC2540 Android上的读数值失败,状态= 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆