I have a strange problem.
I'm writing a app that receive text info from a bluetooth LE connected device, answering to a request.
It work, I receìve the text and i store it in a variable. If I print this text in a label for debug i see the entire text corrected.
But I must to extract some info from text, So i use "Split text at..." in order to split my text in a list with some elements.
My problem is that I can split only first part of my string, until the CR and LF.
If i try to read a index higher, It seems to work (i see the correct value in my extraction) but I receive the error
" Attempt to get item number 3 of a list of length 1: ($V $V20180915 OK*74) Note: You will not see another error reported for 5 seconds."
Please note that I see in the message only the first part of my text! until CR and LF!
I tried to replace CR and LF in my text with null or other characters. I also seems to work As i see in my debug the text without CR and LF but every operation on text, extract from index or create list, work but give me error.
I repeat because this is the strange: It work (If i assign to a label my extracted text is correct) but app give me error and it stop execution!
Last thing, same code but with bluetooth 2.0 is working but because the difference from 2.0 and 4.0 I must rewrote a lot.
this is by Block with problem. As you can see, i removed all undesidered character but index handlig give me error.
In my DEBUG windows I see CORRECT value, so code are working. The error is strange.
Your messages are limited in length by the MTU (Maximum Transmission Unit).
See here for how to get a longer MTU:
The trailing 's' on stringValues tells us that it is a list, and you have to traverse it using either a For Each Item in List loop or by Select Item n From List block in a For Each number n from 1 to length of list stringValues.
That's why you got those ( )'s. They are AI2's way of rubbing your nose in sloppy list handling.
If you can't increase your MTU length, you will need to reassemble the list of incoming text fragments into a long global buffer variable, with this code sequence:
When BLE Strings Received:
For each fragment in list stringsReceived
set global BLEbuffer to JOIN(BLEbuffer, fragment)
end For Each
While CONTAINS(BLEbuffer, '\r\n') do
split BLEbuffer at first '\r\n'
process item 1 of the split result as a complete message
set BLEbuffer to item 2 of the split result.
end While
Here's I assume '\r\n' (CRLF) is your message delimiter.
Adjust to taste.
Dear friend,
thank you for your answer. I know that MTU exist, but I cannot change it because my device is BT4.0. And anyway, you cannot have a MTU more than 255 bytes, also with device bluetooth 4.2 (and my message is 1200 char long).
Anyway I solved the problem: with my code, I must wait until all message is received and all work right.