BluetoothSerial locks up after receiving 512 bytes
Posted: Tue Jul 13, 2021 12:53 pm
I'm not sure where to ask for h elp: Arduino or ESP forum. So I post this on both.
I'm using ESP32 and bluetooth to communicate with my Android phone. The program on the phone is created using MIT App Inventor.
When I'm sending long strings (containing JSON) fom ESP32 to the phone, all goes well, regardless how long the string is. When I'm sending long strings from the phone to ESP32, the Bluetooth Serial reception locks up after receiving 512 bytes.
Whenever the ESP_SPP_DATA_IND_EVT event occurs, I'm reading the entire input buffer using
My BT code contains a supervision timer to detect that BT has stopped receiving data for at least 5 seconds before the message is complete. Message completion is detected by counting the opening and closing curly brackets (since all messages are JSON, the message is complete when the count for opening and closing curly brackets is matching). Everything is fine for short messages, but when the message length exceeds 512 bytes BT locks up and my supervision timer fires.
Is this a bug or do I need to take extra steps to receive very long messages?
PS: I'm using the SPP profile on BT Classic
I'm using ESP32 and bluetooth to communicate with my Android phone. The program on the phone is created using MIT App Inventor.
When I'm sending long strings (containing JSON) fom ESP32 to the phone, all goes well, regardless how long the string is. When I'm sending long strings from the phone to ESP32, the Bluetooth Serial reception locks up after receiving 512 bytes.
Whenever the ESP_SPP_DATA_IND_EVT event occurs, I'm reading the entire input buffer using
Code: Select all
while (SerialBT.available()) { // do this until all chars have been consumed
c = SerialBT.read();
if(btIncomingIndex < (SIZE_BT_INCOMING - 2)) { // if char buffer not full (leave room for terminating '\0')
btIncomingChars[btIncomingIndex++] = c; // store the char and increment index
... more code ...
}
Is this a bug or do I need to take extra steps to receive very long messages?
PS: I'm using the SPP profile on BT Classic