Android作为BLE外围设备
问题描述:
我试图创建一个充当蓝牙低功耗(BLE)外设的Android 5(棒棒糖)应用程序。该应用运行在支持BLE外设模式的Nexus 9上。到目前为止,我已经设法宣传一项服务,并允许其他BLE设备成功连接到它。但是,尝试读取特征值时失败。Android作为BLE外围设备
我已检查过该特性是否具有读取属性,并且设置了读取权限。
当使用LightBlue iOS应用程序(https://itunes.apple.com/gb/app/lightblue-bluetooth-low-energy/id557428110?mt=8)时,我设法发现并连接到我的Nexus并查看特征uuid,但未显示该值。
任何帮助将不胜感激。
答
首先检查你的外设模式是广告特征数据通常有三种模式
BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattCharacteristic.PROPERTY_READ,
BluetoothGattCharacteristic.PROPERTY_NOTIFY;
,您可以使用
BluetoothGattCharacteristic.PROPERTY_WRITE |BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY;
为onCharacteristicWriteRequest一旦完成外观与所有模式打造特色( )在建立特性时给出的BluetoothGattServerCallback()中。当中央想要发送数据时,它可以使用WRITE模式将数据写入特征中,并且您将在外设端触发onCharacteristicWriteRequest()回调方法,并且您将在byte []中获得数据,并确保使用btGattServer.sendResponse(device, requestId,BluetoothGatt.GATT_SUCCESS,0,null); 通过检查回调方法中的responseNeeded布尔值。这样数据就从中央传输到外围。
,并从外围数据发送到中央使用通知charatertertistc
BluetoothGattCharacteristic bgc = bluetoothGattService
.getCharacteristic(chartersticUUID);
bgc.setValue(bnd.data);
btGattServer.notifyCharacteristicChanged(centralbluetoothdevice, bgc, false);
。
你有答案吗?我也试图连接2个Android设备,一个作为消费者,另一个作为数据生产者。 – 2015-10-13 06:12:17