我目前正在开发一种将使用蓝牙低功耗的应用程序(在Nexus 4上进行测试).在开始使用Android 4.3中的官方BLE API之后,我注意到在我第一次连接设备后,我很少能够成功连接到该设备或与该设备或任何其他设备进行通信.
按照此处的指南,我可以成功连接到设备,扫描服务和特性,以及读取/写入/接收通知而不会出现任何问题.但是,在断开连接并重新连接后,我经常无法扫描服务/特性或无法完成读/写操作.我在日志中找不到任何内容来说明为什么会发生这种情况.
一旦发生这种情况,我必须卸载应用程序,禁用蓝牙,然后重新启动手机才能再次开始工作.
每当设备断开连接时,我都要确保在BluetoothGatt对象上调用close()并将其设置为null.任何见解?
编辑:
日志转储:对于这些日志,我根据我的手机并在/etc/bluetooth/bt_stack.conf中提升了相关项目的跟踪级别
连接成功 - 重新启动手机并安装应用后首次尝试.我能够连接,发现所有服务/特性,以及读/写.
失败尝试1 - 这是断开上述成功连接后的下一次尝试.似乎我能够发现特征,但是第一次尝试读取时返回了一个空值并且很快就断开了.
失败的尝试2 - 我甚至无法发现服务/特征的示例.
编辑2:
我尝试连接的设备基于TI的CC2541芯片.我获得了TI SensorTag(也基于CC2541),并发现TI 昨天为SensorTag 发布了一个Android应用程序.但是,这个应用程序有同样的问题.我在另外两个Nexus 4上进行了测试,结果相同:第一次或第二次连接SensorTag成功,但是(根据日志)之后无法发现服务,导致各种崩溃.我开始怀疑这个特定芯片是否存在问题?
android bluetooth bluetooth-lowenergy android-bluetooth android-4.3-jelly-bean
我想用一些蓝牙低能量开发套件创建我自己的iBeacon.Apple还没有发布iBeacons规范,但是一些硬件开发商已经反向使用AirLocate示例代码设计iBeacon并开始销售iBeacon开发套件.
那么iBeacon蓝牙配置文件是什么?
Bluetooth Low Energy使用GATT进行LE配置文件服务发现.所以我认为我们需要知道属性句柄,属性类型,属性值,以及iBeacon属性的属性权限.那么,对于UUID为E2C56DB5-DFFB-48D2-B060-D0F5A71096E0的iBeacon,主要值为1,次要值为1,蓝牙GATT配置文件服务是什么?
这是我在Apple论坛和文档讨论中做出的一些假设.
您只需要查看蓝牙外围设备的配置文件服务(GATT)即可知道它是iBeacon.
Major和Minor键在此配置文件服务中的某处编码
有些公司使用iBeacon Dev Kits似乎已经有了这个数字:
希望我们能及时在Bluetooth.org上发布这样的个人资料:https://www.bluetooth.org/en-us/specification/adopted-specifications
reverse-engineering bluetooth ios bluetooth-lowenergy ibeacon
试图掌握与ibeacon(beacon/bluetooth-le/ble)之间距离的基本概念.有关ibeacon可以测量多远的真实文档吗?可以说我距离300英尺...... ibeacon有可能检测到这个吗?
升级到Android版本6.0后,只有在设备上启用了位置服务时,蓝牙低功耗(BLE)扫描才有效.请参阅此处以供参考:Android 6.0上的蓝牙低功耗startScan无法找到设备
基本上,您需要为应用程序以及手机启用权限.这是一个错误吗?是否可以在没有实际启用位置服务的情况下扫描?我不想拥有所有应用的位置.
编辑
我没有提到我正在使用该startScan()
方法BluetoothLeScanner
API 21提供.我可以使用此方法所需的清单中的课程和良好的位置权限.我只是不希望我的应用程序的用户必须在他们的设备(GPS等)上启用位置服务才能使用我的应用程序.
以前,该startScan()
方法将在手机上禁用位置服务的情况下运行并返回结果.但是,在Marshmallow上,相同的应用程序将"扫描"但是静默失败并且在手机上未启用位置服务且课程/精确位置权限仍在清单中时未返回任何结果.
android bluetooth bluetooth-lowenergy android-6.0-marshmallow
我正在尝试制作一个使用Android 新蓝牙低功耗API的应用程序.为此,我开始使用API等级为18的BLE样本.
当我读到Android无法充当外围设备时,我将Android手机置于中央模式,扫描周围的BLE设备.为此,我使用模拟心脏传感器的北欧平台进行了一些测试.一切都以完美的方式运作!
在此之后,我尝试选择iPhone(iOS 7 beta 4)并将其置于外围设备中并模拟心率传感器作为之前的测试.Android应用程序可以看到设备并连接到它.但是在连接激活后,2个设备会在3-4秒内断开连接.除此之外,当我在Android端调用discoverServices()时,不会触发回调!在某些情况下,即使iOS蓝牙芯片处于关闭状态,Android设备也会收到"已连接"事件.这很奇怪.为了证明这一点,我将Nordic Board置于中央模式,并且我能够正确连接到iOS设备,没有任何问题.
会是什么呢?Android或iOS有一些限制,不允许从Android连接到iOS或反之亦然?
谢谢.
编辑:经过一些艰难的测试,我在AOSP页面上提出了一个问题.可以在这里查看
android ios core-bluetooth bluetooth-lowenergy android-4.3-jelly-bean
Android设备是否可以充当iBeacon并了解其他Android设备何时进入其范围?那些其他Android设备是否需要打开蓝牙?
如果客户进入我的商店并且他的设备上没有安装我的应用程序,iBeacon可以工作,还是必须先安装应用程序?有很多客户每天访问我们的商店,但如果他们没有安装我的应用程序,iBeacon概念是否有效?
android bluetooth bluetooth-lowenergy android-bluetooth ibeacon
我正在研究使用多个iBeacons来做一个"粗略"的室内位置的可能性.该应用程序是一种"博物馆"设置,并且能够更容易地形成具有不同对象的位置的网格,然后是单独的信标(尽管这也许不是不可能的).
有没有例子,经验,使用多个信标进行三角测量到某种位置,或者是一些逻辑来帮助我自己编写它的方式?
用于测试的设备:Nexus 4,Android 4.3
连接工作正常,但onCharacteristicChanged
我的回调方法永远不会被调用.但是我正在使用setCharacteristicNotification(char, true)
inside 注册通知onServicesDiscovered
,该函数甚至返回true.
设备日志(当通知应该出现/通过蓝牙设备发送时,实际上根本没有消息):
07-28 18:15:06.936 16777-16809/de.ffuf.leica.sketch D/BluetoothGatt: setCharacteristicNotification() - uuid: 3ab10101-f831-4395-b29d-570977d5bf94 enable: true
07-28 18:15:06.936 4372-7645/com.android.bluetooth D/BtGatt.GattService: registerForNotification() - address=C9:79:25:34:19:6C enable: true
07-28 18:15:06.936 4372-7645/com.android.bluetooth D/BtGatt.btif: btif_gattc_reg_for_notification
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1018
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, registered=1, charUuid=3ab10101-f831-4395-b29d-570977d5bf94
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1016
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1018
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, …
Run Code Online (Sandbox Code Playgroud) android bluetooth bluetooth-lowenergy gatt android-4.3-jelly-bean
是否可以将iOS 7设备作为蓝牙LE外设(iBeacon)运行并在后台进行广告宣传?我已经能够使用下面的代码在前台做广告,并且可以从另一个iOS设备看到它但是一旦我回到主屏幕就停止广告.我确实在plist中添加了蓝牙外设背景模式,但这似乎没有帮助,虽然我得到提示说该设备想要在后台使用蓝牙.我做错了什么,或者这在iOS 7中是不可能的?
peripManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral
{
if (peripheral.state != CBPeripheralManagerStatePoweredOn) {
return;
}
NSString *identifier = @"MyBeacon";
//Construct the region
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:identifier];
//Passing nil will use the device default power
NSDictionary *payload = [beaconRegion peripheralDataWithMeasuredPower:nil];
//Start advertising
[peripManager startAdvertising:payload];
}
Run Code Online (Sandbox Code Playgroud)
这是接收/收听端的代码:
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
{
//Check if we have moved closer or farther away from the iBeacon…
if (beacons.count > 0) {
CLBeacon *beacon …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个通过蓝牙低功耗发送消息的应用程序,然后由我的外设中的UART传递.我按照这里的步骤操作,应用程序扫描并成功找到设备.但是,使用BluetoothGatt = BluetoothDevice.connectGatt(上下文,自动连接,回调)方法的连接失败,logcat说"无法注册回调".
来自:
//device scan callback
private BluetoothAdapter.LeScanCallback btScanCallback = new BluetoothAdapter.LeScanCallback()
{
@Override
public void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord)
{
some stuff
currBtGatt = device.connectGatt(parentActivity, false, btGattCallback);
}
};
Run Code Online (Sandbox Code Playgroud)
和Gatt回调:
//GATT callback
private BluetoothGattCallback btGattCallback = new BluetoothGattCallback()
{
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{
// if connected successfully
if(newState == BluetoothProfile.STATE_CONNECTED)
{
//discover services
updateStatus("Connected");
gatt.discoverServices();
}
else if(newState == BluetoothProfile.STATE_DISCONNECTED)
{
updateStatus("Disconnected");
}
}
@Override …
Run Code Online (Sandbox Code Playgroud)