如何将这些特性写入android中的BLE GATT服务器?
我正在研究蓝牙低能量GATT,以便与芯片进行通信。我可以读取芯片的响应,但我无法将特征发送到该芯片,也无法通知某些特征。我只能帮忙如何将这些特性写入android中的BLE GATT服务器?,android,bluetooth-lowenergy,gatt,Android,Bluetooth Lowenergy,Gatt,我正在研究蓝牙低能量GATT,以便与芯片进行通信。我可以读取芯片的响应,但我无法将特征发送到该芯片,也无法通知某些特征。我只能帮忙 提前感谢。假设您的BluetoothGattServer设置正确,服务注册的特征以及添加到BluetoothGattServer的服务,下面是向通知特征发送一些数据的示例: private static final UUID serviceUuid = UUID.fromString("SOME-SERVICE-UUID"); private s
提前感谢。假设您的BluetoothGattServer设置正确,服务注册的特征以及添加到BluetoothGattServer的服务,下面是向通知特征发送一些数据的示例:
private static final UUID serviceUuid = UUID.fromString("SOME-SERVICE-UUID");
private static final UUID characteristicUuid = UUID.fromString("SOME-CHAR-UUID");
private BluetoothGattServer gattServer;
private BluetoothDevice peerDevice;
public void sendNotification(byte p1, byte p2, byte p3, byte p4, int correlationid) {
ByteBuffer bb = ByteBuffer.allocate(8);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.put(p1).put(p2).put(p3).put(p4).putInt(correlationid);
BluetoothGattCharacteristic notifyingChar = gattServer.getService(serviceUuid).getCharacteristic(characteristicUuid);
notifyingChar.setValue(bb.array());
gattServer.notifyCharacteristicChanged(peerDevice, notifyingChar, false);
}
在BluetoothGattServerCallback中发送数据时,您将收到一个事件。onNotificationSent
方法:
@Override
public void onNotificationSent(BluetoothDevice device, int status) {
super.onNotificationSent(device, status);
Log.d("SVC", "BluetoothGattServerCallback.onNotificationSent");
}
假设您的BluetoothGattServer设置正确,服务注册的特征以及添加到BluetoothGattServer的服务,下面是向通知特征发送一些数据的示例:
private static final UUID serviceUuid = UUID.fromString("SOME-SERVICE-UUID");
private static final UUID characteristicUuid = UUID.fromString("SOME-CHAR-UUID");
private BluetoothGattServer gattServer;
private BluetoothDevice peerDevice;
public void sendNotification(byte p1, byte p2, byte p3, byte p4, int correlationid) {
ByteBuffer bb = ByteBuffer.allocate(8);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.put(p1).put(p2).put(p3).put(p4).putInt(correlationid);
BluetoothGattCharacteristic notifyingChar = gattServer.getService(serviceUuid).getCharacteristic(characteristicUuid);
notifyingChar.setValue(bb.array());
gattServer.notifyCharacteristicChanged(peerDevice, notifyingChar, false);
}
在BluetoothGattServerCallback中发送数据时,您将收到一个事件。onNotificationSent
方法:
@Override
public void onNotificationSent(BluetoothDevice device, int status) {
super.onNotificationSent(device, status);
Log.d("SVC", "BluetoothGattServerCallback.onNotificationSent");
}
首先,我强烈建议您使用令人惊叹的Bluetooth LE开源库,名为。这将使整个过程更加容易 在项目中包含该库后,您将需要执行以下操作:
writeCharacteristic()
方法写入所需的字节设备。建立连接(错误)
.flatMap(rxBleConnection->rxBleConnection.setupNotification(characteristicUuid))
.doOnNext(通知可观察->{
//已设置通知
})
.flatMap(notificationObservable->notificationObservable)//{
//给定特性已发生变化,以下是值。
},
可丢弃->{
//在这里处理错误。
}
);
他们的Github页面上有大量信息,他们也有自己的。首先,我强烈建议您使用令人惊叹的Bluetooth LE开源库,名为。这将使整个过程更加容易 在项目中包含该库后,您将需要执行以下操作:
writeCharacteristic()
方法写入所需的字节设备。建立连接(错误)
.flatMap(rxBleConnection->rxBleConnection.setupNotification(characteristicUuid))
.doOnNext(通知可观察->{
//已设置通知
})
.flatMap(notificationObservable->notificationObservable)//{
//给定特性已发生变化,以下是值。
},
可丢弃->{
//在这里处理错误。
}
);
他们的Github页面上有大量信息,他们也有自己的。请指定您使用的蓝牙设备/芯片。记住,如果它是一个定制芯片,你从一个供应商-检查与供应商的细节。没有人能帮到这个有限的信息。嗨,他们在BoreCam芯片和CoreCam芯片中提供了一些MAC地址。我不知道BoreCam是什么,除非是Broadcom。如果没有诸如实际制造商和型号之类的详细信息,也没有人能帮助您详细说明您的尝试。它是否像beacon一样为您提供ff2/ff1等服务?请指定您使用的蓝牙设备/芯片。记住,如果它是一个定制芯片,你从一个供应商-检查与供应商的细节。没有人能帮到这个有限的信息。嗨,他们在BoreCam芯片和CoreCam芯片中提供了一些MAC地址。我不知道BoreCam是什么,除非是Broadcom。没有诸如实际制造商和型号之类的细节,也没有人能帮助你详细展示你尝试过的产品。它像灯塔一样为你提供ff2/ff1这样的服务吗?
device.establishConnection(false)
.flatMap(rxBleConnection -> rxBleConnection.setupNotification(characteristicUuid))
.doOnNext(notificationObservable -> {
// Notification has been set up
})
.flatMap(notificationObservable -> notificationObservable) // <-- Notification has been set up, now observe value changes.
.subscribe(
bytes -> {
// Given characteristic has been changes, here is the value.
},
throwable -> {
// Handle an error here.
}
);