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

Any bugs you encounter with Flowcode should be discussed here.
mnfisher
Valued Contributor
Posts: 953
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

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

Post by mnfisher »

Just noticed that 'make a local copy' is ticked for PrintStr str.. This is not needed (and best avoided....)
BTCast.fcfx
(11.21 KiB) Downloaded 109 times
This does seem to print reliably to BT :-)

Martin

stefan.erni
Valued Contributor
Posts: 755
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

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

Post by stefan.erni »

Hi Martin

Very good. I will gladly use your suggestion

For a slow data transfer I like to use the option with the string.
With Flowcode it is very easy to create a string that contains the values ​​of several channels. A comma can also be inserted

Sendstring=ToString$(value1) + "," + ToString$(value2) + "," + ToString$(value3) + "\r\n"

But the values ​​must first be brought to the same length. Simply add a leading "0" or leading space
This means that the value 50 becomes 050.

To get a new line on the end, add the characters for it "\r\n"

For example "150,050,300\r\n"

This sent string can be easily viewed with a terminal program and also logged into a text file. If you save the text file with .csv instead of .txt, you even have a simple Excel file

But the string can also be easily converted back into data. All you have to do is split the string back into integer values.
Value 1 = StringToInt$(string position 0 with length 3)
Value 2= StringToInt$(string position 4 with length 3)
Value 3= StringToInt$(string position 8 with length 3)

For fast data transfer I use blocks that are as large as possible and hold the integer value. With the ESP32 Bluetooth, sending 32Kbyte blocks work every 300mSec.it's not so fast.
I googled it, it has to do with DMA and cache(maybe). There is certainly room for improvement with Flowcode

I'll leave that to Ben

With the crash, I agree with you here too

I'll leave that to Ben
Hopefully Ben and co. can come up with a proper solution..
regards

Stefan

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

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

Post by mnfisher »

Hi Stefan,

Yes that's a neat way to make easily readable data streams - though it does limit the range of values a bit (0..999 for three digits) and also involve more data being transferred (4bytes instead of 2 so can only be 50% speed)

Easy to pull the data out on a loop as well..
  • Value[. i] =StringToInt$(data[. i*4], 3)
I think using a single PutBytes for a string as per example is the way to go in combination with checking cong... The code above ran without errors for a couple of days - so I think we were right about the cause of the errors too..

Martin

BenR
Matrix Staff
Posts: 1733
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 439 times
Been thanked: 602 times

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

Post by BenR »

Hi Guys,

Many thanks for working on this and posting your results. I've applied Martins workaround code to the SendString function and hopefully that will help to make it more reliable now.

Interesting the receive string is also having problems, I'll see if I can investigate this a bit more thoroughly.

stefan.erni
Valued Contributor
Posts: 755
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

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

Post by stefan.erni »

Hi Ben

Sending long string is working now. Thanks a lot.

Receiving long string is working also if the receiving command and string is long enough.
But if the command is dimensioned too short, it can crash an it's need a hardware reset.

regards

Stefan
BT_rec_2022-03-24_15-33-38.jpg
BT_rec_2022-03-24_15-33-38.jpg (45.86 KiB) Viewed 1731 times

Post Reply