This topic is specifically created to ask Cattledog a question / help because I was not able to send a message directly.
I have been doing extensive research and every time I find an answer in this or another forum, your name comes up among the responses that most often solve the problem (incl. a problem someone was having with esp32 freezing if the transmitted data was greater than 512 bytes), so naturally I assume that you must have extensive knowledge in the field of arduino / esp32 programming and bluetooth.
At first I tried to do this using BLE, but I quickly realized that it's very complicated plus it is designed for short bursts of transmission to save battery power, and although I got it to send data to some level, it turned out it would take too much idle time between transmissions so it wasn't a good solution. So I decided to use classic bluetooth / spp, which seems to be designed for this purpose.
I am trying to design / build a continuous serial data transmitter to link one rc radio transmitter to another transmitter. I have linked them using rx/tx and gnd serial wire, and it works great (it's one directional so only 1 tx wire and gnd is actually enough). The format is 100,000 baud, 8E2.
I am using "serial-bt".read() / write() and serial.read() write to accomplish this. (For testing purposes only) if I read the serial data on serial1 or the sending board and mirror it/write to the serial2 port of the same board, everything works fine. The read/write action keeps the data frame timed correctly, so it works ok.
The data is 25 bytes long every frame (12 bits per byte incl. the start bit, 8 data bits, 1 parity bit and 2 stop bits), so total of 300 bits at 100 kbauds and takes exactly 3 milliseconds to read/write. Each frame has an updated rate of 9 ms, so there is 6 ms of idle time (logic high for 6 ms).
After doing research and learning how to use the 64 bit timer of the esp32, I timed each task. The read on serial1 takes exactly 3ms, send to bt.write() takes another 1.5 ms, if I write to serial2 on the same board, it takes another 3 ms, and each "loop" cycle, depending on what all I do, takes about 9 to 10 ms.
My received signal on the receiving board was very erratic and did not reproduce the sent signal, after lots of reading I realized that there's no time reference on the 2nd board, so I have to use a timer to create the 9 ms update rate signal frame by use of timers, thd read/write tasks alone can't create a signal frame like on just one board. So I started timing the tasks on the receiving esp32 board. Everything seems reasonable, except the bt.read() task. For the 300 bits (25 bytes and writing them into an array buffer of  ) takes anywhere from 27 milliseconds to 42 milliseconds. It shouldn't take that long if bluetooth is capable of 1 Mbps or anything near that, but I don't think the transmission actually takes that long, it's the processing. I do all the reading/writing in the main loop. I tried just receiving and storing 1 byte of the 25, and it took 4 ms still, which seems long for just 1 byte. The remaining serial.write() and any other tasks take almost no time.
Any idea why receiving 300 bits (100 of which is stop bits and other overhead bits, so only 200 data bits) takes so long? When I try to reconstruct the signal frame with a refresh rate of 9 ms, if getting the new frame takes 27 to more than 40 ms, it would make for a very "slow" refresh rate. I know this can be done with classic bluetooth because some rc radios have internal bluetooth connection modules.
I use the regular server/client in the serial BT examples of the arduino IDE to establish a connection between the 2 esp32 boards, that part seems to work pretty well and easily. Any help would be appreciated to figure out how to speed up the reception part. If you know any additional info to see how I proceed, let me know. It's pretty simple so far though, just read 25 bytes from serial when available, send to bluetoothSerial, then the opposite on the receiving board, all in the main loop other than the initial setup.