0

I am working on an Android app that needs to send data from an accelerometer to an arduino. The problem is that the string is sent only half-way moment at which the next transmission starts. Anything I tried like SystemClock.sleep(); did not help, meaning that any next line would interrupt the transmission of the string.

    public void onSensorChanged(SensorEvent event) {
        acceler[0]=event.values[0];
        acceler[1]=event.values[1];
        acceler[2]=event.values[2];
        transmit();
    }

    private void transmit() {
        String str =":" + acceler[0] + " " + acceler[1] + " " + acceler[2] + "\n\r";
        final byte[] tx = str.getBytes();
        if(mConnected) {
            TXcharact.setValue(tx);
            mBluetoothLeService.writeCharacteristic(TXcharact);

        }
    }
Antoniu Fic
  • 39
  • 1
  • 3

1 Answers1

0

It depends on BLE specification, but your str seems too long to send at once.

Maximum packet length for Bluetooth LE?

"BLE allow you transfer maximum is 20 bytes."

"You are correct that the BLE specification doesn't allow write operations to exceed 20 bytes."

So, split them and use some waiting queue to store them.

Community
  • 1
  • 1
Toris
  • 2,348
  • 13
  • 16