Android Question Android Bluetooth outputStream sleep between bytes

MarcinM

New Member
Hi !
I have HC-05 BT device, work in SPP mode. I need to have 4 ms space between send bytes. Device sending bytes - but space between bytes is from 0.4 ms to 400 ms. I'm using also USB-RS interface via USB OTG with FTDI chip - and in this case space between bytes is 4 ms +- 0.5 ms - and this is acceptable for me. Any ideas to resolve it ?
Java:
    private class WriteThread extends Thread{
    byte[] data;
    WriteThread(byte[] dataToSend)
    {
        this.data = dataToSend;
        setPriority(Thread.NORM_PRIORITY);
    }
    public void run()
    {
        if (data[0] == (byte)0xB8 && data[1] == (byte)0x12)
        {
            {
                try {
                    for (int i =0 ;i < data.length ; i++) {
                        outputStream.write(data[i]);
                        outputStream.flush();
                        this.sleep(4);
                    }
                } catch (Exception ex) {
                    Log.d("SLEEP", Objects.requireNonNull(ex.getMessage()));
                }
            }
        }
        else
            try {
                outputStream.write(data);
            } catch ( Exception ex)
            {
                Log.d("SLEEP", Objects.requireNonNull(ex.getMessage()));
            }
    }
}
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…