Hi Ben
If I send a string by bluetooth to the computer it's working fine if the string is less than 12char.
But if I send a string with more than 12 char, the ESP Bluetooth crash and need a reset(power on/off)
Sending a array of char is working fine even it's more than 20 byte.
I tested 512byte and it was working fine
regards
Stefan
ESP32 Bluetooth sending a string crashes if string len >12char
-
- Valued Contributor
- Posts: 997
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
-
- Valued Contributor
- Posts: 1454
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 708 times
Re: ESP32 Bluetooth sending a string crashes if string len >12char
Something is still wrong with the Bluetooth SendString.
If I send "Hello world\r\n" the serial program received a variable number of bytes from 'Hello' most commonly up to the full string occasionally.
Using SendArray works perfectly..
Looking at the code - SendString uses SendByte where SendArray uses PutBytes..
SendString also declares a 1 byte array buff - although this is never used?
Martin
If I send "Hello world\r\n" the serial program received a variable number of bytes from 'Hello' most commonly up to the full string occasionally.
Using SendArray works perfectly..
Looking at the code - SendString uses SendByte where SendArray uses PutBytes..
SendString also declares a 1 byte array buff - although this is never used?
Martin
-
- Valued Contributor
- Posts: 997
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
Re: ESP32 Bluetooth sending a string crashes if string len >12char
Hi Martin
I have two device. One with a PIC32 and a RN4677 BT- Modul, the another device is a ESP32 (Bluetooth integrated)
With the RN4677 BT- Modul sending string is working fine. Maybe this has something to do with a buffer
regards
Stefan
I have two device. One with a PIC32 and a RN4677 BT- Modul, the another device is a ESP32 (Bluetooth integrated)
With the RN4677 BT- Modul sending string is working fine. Maybe this has something to do with a buffer
regards
Stefan
-
- Valued Contributor
- Posts: 1454
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 708 times
Re: ESP32 Bluetooth sending a string crashes if string len >12char
Hi Stefan,
The problem occurs when sending from the ESP32 can you test this? - I don't think it's a reception issue as SendArray data is received perfectly.
(I used Blue Serial under Android to check the data..)
Martin
The problem occurs when sending from the ESP32 can you test this? - I don't think it's a reception issue as SendArray data is received perfectly.
(I used Blue Serial under Android to check the data..)
Martin
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 501 times
- Been thanked: 686 times
Re: ESP32 Bluetooth sending a string crashes if string len >12char
Many thanks for letting us know. I've replicated the issue here and am now trying to work around it.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 501 times
- Been thanked: 686 times
Re: ESP32 Bluetooth sending a string crashes if string len >12char
Ok after a fair bit of digging and chopping and changing the CAL code I wasn't able to solve the problem. Even long delays and trying to add blocking calls to not call the write function until the last write function was complete did not yield any positive results.
However I did find a couple of leads via Google and found editing a line in the IDF library that does solve the problem.
It seems to be to do with flow control credits which are negotiated by the client and so the problem may not always manifest as we are seeing. Note I too was using an Android phone based serial monitor to see the data output.
Anyway to solve the problem I edited the file here.
esp-idf\components\bt\host\bluedroid\stack\rfcomm\rfc_utils.c
On line 468 comment out the line and save.
The end function now looks like this.
and now after compiling again it's working perfectly.
For reference this was the page I found with the fix.
https://www.esp32.com/viewtopic.php?t=5613
However I did find a couple of leads via Google and found editing a line in the IDF library that does solve the problem.
It seems to be to do with flow control credits which are negotiated by the client and so the problem may not always manifest as we are seeing. Note I too was using an Android phone based serial monitor to see the data output.
Anyway to solve the problem I edited the file here.
esp-idf\components\bt\host\bluedroid\stack\rfcomm\rfc_utils.c
On line 468 comment out the line and save.
Code: Select all
p_port->tx.peer_fc = TRUE;
Code: Select all
void rfc_dec_credit (tPORT *p_port)
{
if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) {
if (p_port->credit_tx > 0) {
p_port->credit_tx--;
}
if (p_port->credit_tx == 0) {
//p_port->tx.peer_fc = TRUE;
}
}
}
For reference this was the page I found with the fix.
https://www.esp32.com/viewtopic.php?t=5613
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Valued Contributor
- Posts: 997
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
Re: ESP32 Bluetooth sending a string crashes if string len >12char
Hi Ben, Hi Martin
I have tested
I made the line as comment, but my sdkconfig was rewritten so I had to make the correction for Blutooth SPP again and long string sending works now. Then I made the lines active again and it still works. The RFC_utils.c may not be compiled every time.
a short time ago i was asking for an ESP32 pico. I think this is a good idea to prevent such a problem with the sdkconfig file
viewtopic.php?f=4&t=375&start=10
regards
Stefan
I have tested
I made the line as comment, but my sdkconfig was rewritten so I had to make the correction for Blutooth SPP again and long string sending works now. Then I made the lines active again and it still works. The RFC_utils.c may not be compiled every time.
a short time ago i was asking for an ESP32 pico. I think this is a good idea to prevent such a problem with the sdkconfig file
For this ESP32 PICO D4:
There is currently no BLE profile supported in Flowcode 9,
Unfortunately, the standard configuration from Flowcode for all ESP32 Device is set to Bluetooth BLE.
The configuration must always be changed manually to Bluetooth SPP and if you are not careful it will be set back later during compilation from Bluetooth SPP back to Bluetooth BLE.
Wouldn't the standard for Bluetooth be better
BluetoothSPP (and without debugger messages)?
viewtopic.php?f=4&t=375&start=10
regards
Stefan
-
- Valued Contributor
- Posts: 997
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
Re: ESP32 Bluetooth sending a string crashes if string len >12char
Hi Ben,
You wrote:
regards
Stefan
You wrote:
I did not understand that completely. Do you solve the problem somehow? or do I have to change this file?Many thanks for letting us know. I've replicated the issue here and am now trying to work around it.
regards
Stefan
-
- Valued Contributor
- Posts: 997
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 190 times
- Been thanked: 217 times
Re: ESP32 Bluetooth sending a string crashes if string len >12char
Hi Ben
The file is changed but still a problem sending longer string. So I tried send
P1 15x char 0 //and it crashed
P2 15x byte char "0" (decimal 48) //working fine
P3 5x char 0 //working fine
Testet on Windows and Android
regards
Stefan
The file is changed but still a problem sending longer string. So I tried send
P1 15x char 0 //and it crashed
P2 15x byte char "0" (decimal 48) //working fine
P3 5x char 0 //working fine
Testet on Windows and Android
regards
Stefan
Code: Select all
/*******************************************************************************
**
** Function rfc_dec_credit
**
** Description The function is called when a UIH frame of user data is
** sent. It decrements the credit count. If credit count
** Reaches zero, peer_fc is set.
**
** Returns void
**
*******************************************************************************/
void rfc_dec_credit (tPORT *p_port)
{
if (p_port->rfc.p_mcb->flow == PORT_FC_CREDIT) {
if (p_port->credit_tx > 0) {
p_port->credit_tx--;
}
if (p_port->credit_tx == 0) {
//p_port->tx.peer_fc = TRUE;
}
}
}