Hi. When transmitting BLE data, sending separately one by one:
"abcdef"
"abcdef"
Sometimes they go to the buffer in this form: b'abcdefabcdef '
Should I use some sort of separator / delimiter? If so, what exactly?
I was thinking about "\n" or "#" but in the future I want to transfer files so I don't know if that's a good solution. Thanks for tips.
BLE data - buffer.
Re: BLE data - buffer.
I'm assuming you're using the buffer mode on the characteristic. (i.e. append=True on https://docs.micropython.org/en/latest/ ... set_buffer)
What you're describing is a fundamental thing in the design of any protocol. The two most common options are to either length-prefix your data (i.e. some number of bytes containing an integer with the length, followed by that many bytes of data), or like you say, to use a delimiter.
Or you can use both together.
Re: BLE data - buffer.
Yes apeend is set to True, but there is one more thing. When I have the buffer set to len = 100, I will send a packet which has e.g. 80 bytes, then it will send another 80 bytes packet, I receive that 80 bytes will come, 20 from the next packet is added/append, and the rest of the second, i.e. 60, does not arrive .. .. So it looks like when my buffer is set to 100, I have to send 100 bytes too, right?
Re: BLE data - buffer.
If the buffer is set to len=100, then two 80 byte payloads arrive, then the last 60 bytes of the second payload will be lost.prem111 wrote: ↑Mon Nov 23, 2020 2:06 pmYes apeend is set to True, but there is one more thing. When I have the buffer set to len = 100, I will send a packet which has e.g. 80 bytes, then it will send another 80 bytes packet, I receive that 80 bytes will come, 20 from the next packet is added/append, and the rest of the second, i.e. 60, does not arrive .. .. So it looks like when my buffer is set to 100, I have to send 100 bytes too, right?
You can send as many bytes as you like, but you need to rate limit how quickly you're sending (and/or read the data faster out of the buffer using gatts_read).
You might also be interested in the L2CAP channel support which was just merged upstream last night. (But unfortunately only for STM32 for now, ESP32 support might come later)