我試圖獲得一個Android Nexus 5X應用程序與NRF51芯片一起工作,並面臨一些問題,特別是寫入特性。真的希望得到一些幫助。如何解決Android和Nordic nRF51的特徵寫入失敗?
我想通過應用程序在nrf上設置一個實時時鐘(RTC)。給我的關於GATT服務特點的細節如下:
屬性:讀 - 強制性,寫 - 強制性,寫無響應 - 排除,簽名寫入 - 排除,通知 - 排除,表示 - 排除,可寫輔助 - 排除,廣播 - 排除。
安全: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); }
嗨,謝謝你指出。我在我的原始代碼中這樣做,但忘了在上面的示例代碼片段中。問題在於,在執行寫入特性之前,我必須等待讀取回調。但是,獲得寫入成功後,我收到一個錯誤 - 在onWriteCharacteristic()回調期間發生錯誤133.任何建議將不勝感激。謝謝。 –
Android Ble Ble堆棧無法處理並行請求。因此,我們需要將讀/寫請求序列化爲可堆棧。請確保您的請求已被序列化,這意味着在發送下一個請求之前您需要等待幾秒鐘或做出響應。你可以使用延遲或隊列來實現這一點。 – 7383
是的,我只使用readcharacteristic(),它的工作,所以感謝。我是否正確地說,在繼續使用其他BLE方法之前,需要回調onWrite/ReadCharacteristic()? –