标签: gatt

即使在调用disconnect()之后,Android BLE BluetoothGatt对象仍保持连接并触发onCharacteristicChanged()

我正在尝试在退出应用程序时断开特征通知.以下是我在exitCleanup()函数中的操作方法:

if (btGatt != null && mWriteChar != null) {
   boolean b=btGatt.setCharacteristicNotification(mWriteChar, false);
   Log.w("AppInfo", "Exiting and Unsubscribing: " + b);
}
Run Code Online (Sandbox Code Playgroud)

日志显示:Exiting and Unsubscribing: true.到现在为止还挺好.然后,我尝试使用以下方法完全断开GATT对象:

if (btGatt != null && btManager!=null && btManager.getConnectionState(btDevice, BluetoothProfile.GATT) != BluetoothProfile.STATE_DISCONNECTED ) {
    //Making sure that gatt and bt manager are still with us
    //Also making sure that the connection state is NOT disconnected
    btGatt.disconnect();
    btGatt.close();
    Log.w( "AppInfo", "FINISHING. Connection state=" + btManager.getConnectionState(btDevice, BluetoothProfile.GATT) );
}
Run Code Online (Sandbox Code Playgroud)

这是事情变得奇怪的地方.日志现在显示以下内容:FINISHING. Connection state=2,表示BluetoothDevice仍然连接.

这是一个问题,因为当应用程序完成并销毁所有资产时,BluetoothGattCallback仍会继续在幕后接收通知.首先它抛出以下NullPointerException:

04-25 …
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy gatt

7
推荐指数
1
解决办法
1439
查看次数

是否可以与一台 GATT 服务器建立多个 BLE 连接?

是否可以有多个 GATT 客户端连接到一台 GATT 服务器?

例如,传感器可以是 GATT 服务器。我希望同时连接多部智能手机,以便访问传感器上存储的不同服务。

我检查了蓝牙的核心规范,但找不到任何有用的信息。

提前致谢!

bluetooth bluetooth-lowenergy gatt

7
推荐指数
1
解决办法
4588
查看次数

Android BLE API:Autoconnect不适用于所有设备?

我有两个外围设备,比如device1和device2以及一个用于中心角色的Android设备.Android可以通过BluetoothDevice连接到两者.connectGatt()方法与autoConnect = false.

问题是 - 虽然autoConnect功能适用于device1,但设备2甚至不能连接autoConnect = true一次.

在任何一方都没有调用onConnectionStateChange回调(android和device2).广告和扫描响应数据包已在设备2中自定义,是否导致问题?虽然我们知道,自主连接的设置完全在中心侧提供,外围设备与其无关,外围设备的改变也改变了中心侧的自动连接行为.

任何见解?提前致谢.

peripherals bluetooth-lowenergy gatt android-4.3-jelly-bean

6
推荐指数
0
解决办法
2660
查看次数

同步从BLE设备读取多个特征(推荐的Android方法)

我正在开发一个从BLE设备读取数据的android应用程序.我在这里遇到了很多关于如何读取多个特征的解决方案,其中大部分都是建议的队列.

我确实实现了Queue方法,一切都在我的代码中正常工作.我开始这个主题的原因是找到最好的和最有效的解决方案,并清除我对某些BLE服务特性如何工作的疑虑.

我已经将以下两个链接作为参考,这有助于我使我的代码工作.

来源1:

Android:BLE如何读取多个特征?

来源2:

Android BLE API:未收到GATT通知

我的要求是阅读心率测量电池水平.最初我尝试将心率和电池特性添加到队列中,然后为每个添加的元素调用读/设置方法.

主要活动:

private void displayGattServices(List<BluetoothGattService> gattServices) 
{
   // get the required service & characteristics
   ................
   ................  

   // add the characteristics via Queue
   hRM_characteristicReadQueue.add(characteristics);

   // Initiate read/set methods
   read_Characteristic();   
};

private void read_Characteristic()
 {
   bluetoothHDPService.read(hRM_characteristicReadQueue.element());
   bluetoothHDPService.set(hRM_characteristicReadQueue.element(),true);
   hRM_characteristicReadQueue.remove();
};
Run Code Online (Sandbox Code Playgroud)

bluetoothHDPService:

public void read(BluetoothGattCharacteristic characteristic) 
 {
    if (bluetoothAdapter == null || bluetoothGatt == null) 
    {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    };

    bluetoothGatt.readCharacteristic(characteristic);
};

public void set(BluetoothGattCharacteristic characteristic, boolean enabled) 
{ …
Run Code Online (Sandbox Code Playgroud)

service android synchronous bluetooth-lowenergy gatt

6
推荐指数
0
解决办法
5103
查看次数

蓝牙 GATT 断开 onConnectionStateChange 未调用

我正在尝试通过安排计时器并BluetoothGatt.disconnect()手动调用在我的蓝牙 GATT 服务上实现我自己的超时。但是,如果从远程设备触发断开连接,则不会像通常发生的那样调用回调。还有一个日志来自BluetoothGatt调用断开函数

D/BluetoothGatt? cancelOpen() - device: 00:07:80:04:1A:5A
Run Code Online (Sandbox Code Playgroud)

这是我断开连接的代码

private void scheduleDisconnect() {
    isTimerRunning = true;
    disconnectTimer = new Timer();
    disconnectTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            isTimerRunning = false;
            disconnect();
        }
    }, 2000);
}
Run Code Online (Sandbox Code Playgroud)

为什么onConnectionStateChange不叫?它适用于另一个回调和操作

android bluetooth bluetooth-lowenergy gatt

6
推荐指数
1
解决办法
7575
查看次数

更改蓝牙低能量gatt超时或刷新读取流以更快地检测断开事件

我正在寻找一种方法来刷新应用程序从Ble设备接收的特征,或者至少从数据中知道连接已经丢失,除非它在断开连接后大约15秒.如果有办法改变gatt连接超时,那将会更好.

要以不同的形式重复,我想要一个解决方案(或一个可以解释的链接)来检测BLE设备的断开速度比当前的超时值更快,通过查看我得到的值是否是新的通过刷新特性,或改变gatt侧的断开超时,所以我可以看到它在一秒内断开连接以触发其他代码.

android bluetooth-lowenergy gatt

6
推荐指数
1
解决办法
3437
查看次数

C中的蓝牙低功耗 - 使用Bluez创建GATT服务器

我正在尝试在我的Linux机器上使用GATT来设置具有大量特征的自定义服务.

使用这个问题及其链接的问题,我能够识别出我需要编写的代码(利用该gatt_service_add()函数).

我创建了一个名为gatt_service.c的独立文件,并编写了我认为我需要的代码.但是,我无法弄清楚如何将我的代码链接到Bluez库以编译和运行我的解决方案.例如,这个站点(虽然不是用于BLE开发)使用-lbluetoothgcc参数链接libbluetooth ,我无法找出链接的内容以使我的代码工作.

我没有发布任何样品,因为我不确定要发布什么 - 如果有任何要求,或者我没有提及,请告诉我.

提前致谢.

编辑 - 更多信息:

在评论之后,我使用插件/时间作为基础为我自己的"Broadcaster服务"编写我自己的文件.完整代码位于:这里(我不知道在答案中放置哪些代码!).

我的编译命令是:( gcc gatt_broadcaster_service.c -Wall -o gatt_broadcaster_service -lbluetooth 'pkg-config --cflags --libs glib-2.0' -I/home/alexander/Documents/bluez-5.29/lib包括修复此处报告的问题的glib位).

我得到的错误是:gatt_broadcaster_service.c:11:27:致命错误:lib/bluetooth.h:没有这样的文件或目录#include"lib/bluetooth.h"

我的C文件存储在Documents中,我的研究告诉我它找不到lib/bluetooth.h,因为它没有找到正确的位置(这个谈论在文件不是时使用包含标志的编译器在一般的位置,但我无法做到这一点.

再次感谢!

linux bluetooth-lowenergy bluez gatt

6
推荐指数
1
解决办法
2万
查看次数

最大数量 使用BlueZ进行BLE连接

Q1.使用BlueZ 5.34连接到BLE外设时,BLE中央设备是否存在连接限制?

我的问题是使用BlueZ非白名单的一般连接功能.

Q2.如果没有.连接取决于控制器.有没有找到Max限制的方法?

Q3./主机BlueZ或Bluedroid是否可以限制最大数量.控制器支持的LE连接?

Q4.如果LE设备存在连接限制,则作者的意思是"无固有限制",如下面引用的块所示.

来自Robin Heydon BLE开发人员手册的信息

这也意味着给定设备可以同时与之通信的设备数量不应存在固有限制.如果一个设备想要与另一个设备通话,那么它应该能够做到这一点,不用担心只有七个可能的从设备可以同时连接,这是经典蓝牙所施加的限制.

实验:如下面的参考文献中所示,我在使用不同的控制器时也看到了各种LE白名单,32代表可插入usb4btle,24代表内部蓝牙适配器.(使用命令:hcitool lewlsz)在我的测试设置中,我能够连接到12个BLE设备.(我有最多12个BLE外设).我在Ubuntu 15.04中使用BlueZ 5.34并使用了可插入的usbbt4le加密狗.

bluetooth hci bluetooth-lowenergy bluez gatt

6
推荐指数
1
解决办法
2544
查看次数

BLE 连接始终调用断开连接的操作(GATT 配置文件)

我建立了一个 BLE 连接以在设备之间发送数据(大约每 10 秒它们建立一个新连接,发送数据,然后断开连接)并且正常工作正常。但是,几分钟后,设备再也不会连接,并且应该与另一个设备连接的设备正在循环调用“ ACTION_GATT_DISCONNECTED ”(此字符串指的是断开连接的接收器操作)。

在我的接收器中,我有 3 个相关的操作:

@Override
    public void onReceive(Context context, Intent intent) {
        customBluetoothManager = customBluetoothManager.getInstance(context, null, null);
        final String action = intent.getAction();
        Log.d("test", "onReceive");
        if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
            Log.d("test", action);
        } else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
            Log.d("test", action);
        } else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
            Log.d("test", action);
            //....
            //Code to send data after services discovered
            //....
        }
    }
Run Code Online (Sandbox Code Playgroud)

因此,在最初的几分钟内一切正常。首先调用ACTION_GATT_CONNECTED,然后调用ACTION_GATT_SERVICES_DISCOVERED动作,然后设备发送数据,然后断开并释放蓝牙通信通道。问题是,有时,并不总是在同一点(因此我无法找到任何模式来重现这个问题),在循环中总是调用ACTION_GATT_DISCONNECTED,因此永远不会建立通信。

ACTION_GATT_DISCONNECTED被分配在onConnectionSateChange从回调BluetoothGattCallback类:

@Override
        public void onConnectionStateChange(BluetoothGatt gatt, int …
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy gatt

6
推荐指数
1
解决办法
4070
查看次数

我想从我们开发的移动应用程序的 11 字节数据中识别 BLE 车轮和曲柄传感器数据

我想从11 字节数据中识别车轮和曲柄传感器数据。我试图按照下面链接中的拆分来解析我在我们的移动应用程序中获得的 11 字节十六进制数据。

https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.csc_measurement.xml

例如,我尝试了以下方法,

十六进制数据:0x03 6D010000 FC7E 2C01 F87E

Flag-03 ->0000 0011 -> 8bits 所以两者都是真的,因此我们可以得到车轮和曲柄各自的值。

累积车轮转数- 6D 01 00 00 -> 32 位,因此将其转换为十进制我们得到 -1828782080

最后一个轮子事件时间 - FC 7E -> 16 位,因此我们将其转换为十进制 - 64638

累积曲柄转数 - 2C 01 -> 16 位,因此将其转换为十进制我们得到 - 11265

上次曲柄事件时间 - F8 7E -> 16 位,因此我们将其转换为十进制 - 63614

我无法从 BLE 获得实际的车轮和曲柄测量值。我从我遵循的参考链接中了解到的上述程序是否正确?还是我在其他地方错了?我已尽最大努力剖析和解析数据,但不幸的是我无法找到解决方案。请指导我完成这个过程。我们必须做什么才能获得正确的价值?就像我应该用某个数字乘以它吗?我尝试过不同的组合但无法获得。我使用的设备是SunDing515 自行车速度和踏频传感器,带有蓝牙低功耗

android bluetooth-lowenergy gatt android-ble

6
推荐指数
1
解决办法
1090
查看次数