ESP32 Bluetooth sending a string crashes if string len >12char

Post Reply
stefan.erni
Valued Contributor
Posts: 251
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 51 times
Been thanked: 65 times

ESP32 Bluetooth sending a string crashes if string len >12char

Post by stefan.erni »

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

mnfisher
Posts: 195
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 25 times
Been thanked: 101 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by mnfisher »

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

stefan.erni
Valued Contributor
Posts: 251
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 51 times
Been thanked: 65 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by stefan.erni »

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
BT_Capture.JPG
BT_Capture.JPG (85.71 KiB) Viewed 76 times

mnfisher
Posts: 195
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 25 times
Been thanked: 101 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by mnfisher »

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

BenR
Matrix Staff
Posts: 746
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 149 times
Been thanked: 235 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by BenR »

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 Product Page - Flowcode Help Wiki - My YouTube Channel

BenR
Matrix Staff
Posts: 746
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 149 times
Been thanked: 235 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by BenR »

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.

Code: Select all

p_port->tx.peer_fc = TRUE;
The end function now looks like this.

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;
        }
    }
}
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel

mnfisher
Posts: 195
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 25 times
Been thanked: 101 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by mnfisher »

Thanks Ben,

Yes - seems to work AOK :-)

Martin

stefan.erni
Valued Contributor
Posts: 251
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 51 times
Been thanked: 65 times

Re: ESP32 Bluetooth sending a string crashes if string len >12char

Post by stefan.erni »

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
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

Post Reply