我正在尝试让一个安卓Nexus5X应用程序在NRF51芯片上工作,但遇到了一些问题,特别是在写入特征方面。真的希望能得到一些帮助。
我正在尝试通过应用程序在nrf上设置实时时钟(RTC)。关于关贸总协定服务特性的详细信息如下:
属性: Read - Mandatory,Write - Mandatory,WriteWithoutResponse - Excluded,SignedWrite - Excluded,Notify - Excluded,Indicate - Excluded,Write Auxilliaries Excluded,Broadcast -Excluded。
安全性: ENC_NO_MITM
描述符:无
连接到nrf后,我的'onServiceDiscovered()‘实现如下所示。我可以做一个readCharacteristic,这导致了'conCharacteristicRead()‘的调用,但是writeCharacteristic()失败了。将非常感谢您的指导。非常感谢!
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
// Get the characteristic
BluetoothGattCharacteristic loggingRTCCharacteristic = gatt.getService(loggingServiceUUID).getCharacteristic(loggingRTCControlPointCharacteristicUUID);
// Read characteristic (which succeeded, as onReadCharacteristic is invoked)
boolean successFlag = gatt.readCharacteristic(loggingRTCCharacteristic);
// Check for success.
// Set a plausible timestamp.
int year_lsb = 221; int year_msb = 7;
int month = 3;
int dayOfMonth = 4;
int dayOfWeek = 7;
int hour = 9;
int min = 3;
int sec = 15;
byte[] timeStamp = {(byte)year_lsb, (byte)year_msb, (byte)month, (byte)dayOfMonth, (byte)dayOfWeek, (byte)hour, (byte)min, (byte)sec};
logingRTCCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
// This returns a failure. The onCharacteristicWrite() function is not invoked either.
successFlag = gatt.writeCharacteristic(loggingRTCCharacteristic); }发布于 2017-03-05 02:26:34
我猜你错过了下面这行。
logingRTCCharacteristic.setvalue(timestamp)发布于 2017-03-07 21:49:31
确保特征数据不会超出23字节的MTU限制。因为nRF51设备的北欧堆栈(SoftDevice)仅支持23字节的最大MTU值。您的数据大小超出了23个字节。
https://stackoverflow.com/questions/42598852
复制相似问题