После долгих поисков и отсутствия ответов, я предполагаю, что это единственное решение :)
я есть приложение для Android, которое записывает данные в simblee bluetooth.
Ниже код у меня есть:
public void sendData(String data) {
Utils.addLog(TAG,"sending data : " + data);
if (mSerialCharacterstic == null) {
Utils.addLog(TAG,"serial characteristic not found yet!");
return;
}
Utils.addLog(TAG,"starting write data...");
mSerialCharacterstic.setValue(data);
Utils.addLog(TAG,"writing : " + data);
// mGatt.beginReliableWrite();
mGatt.writeCharacteristic(mSerialCharacterstic);
}
/ ******************* /
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Utils.addLog(TAG,"onCharacteristicWrite : " + new String(characteristic.getValue()) + " status : " + status);
// gatt.executeReliableWrite();
Utils.addLog(TAG,"data written");
super.onCharacteristicWrite(gatt, characteristic, status);
}
Все работает правильно (по какой-то причине не работает надежный ключ, но это уже другой вопрос)
Теперь, если я хочу потоковую передачу данных (например, событие onTouch отправляет свет в режиме реального времени)
Единственное решение, которое работает со мной, это сохранение данных в поток в массиве, иOnCharacteriticWrite
отправить следующие данные для отправки.
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Utils.addLog(TAG,"onCharacteristicWrite : " + new String(characteristic.getValue()) + " status : " + status);
// gatt.executeReliableWrite();
Utils.addLog(TAG,"data written");
if (isStreaming && streamQueue.size() > 0) {
streamQueue.remove(0);
Utils.addLog(TAG,"item removed");
Utils.addLog(TAG,"stream size : " + streamQueue.size());
if (streamQueue.size() > 0) {
Utils.addLog(TAG,"streaming next item");
sendData(streamQueue.get(0));
}
else {
Utils.addLog(TAG,"no more items to stream");
didSendFirstSet = false;
}
}
super.onCharacteristicWrite(gatt, characteristic, status);
}
Это работает для меня, но я уверен, что должен быть более надежный способ отправить орех данных, я не смог найти надлежащую документацию для него (в моем коде любая ошибка, которая происходит во время потоковой передачи, остановит весь поток)