My app freezes when I try to receive information via Bluetooth

Hello, I'm working on an app for an uni project and I came across a problem when i try to use Bluetooth, the app just freezes when i press the button that should send a character and receive text from the program.

I'm using and HC-06 module on an LPC-845 board, in my app there's a button to send a char 'a' to the board and then receive a list of times sepparated by a comma, for example, 0900,1030,1120,1450, then, it should put the data on some labels that are distributed across the screen.

The blocks look like this (I'm not putting both at the same time, it's just that i think i cannot upload more than one picture):

I want to use the larger option as it is the one that i need, the second one was just to test if the app at least received all of the string and just pasted it, but it also freezes the app. I've also tried with creating and empty list but it also didn't work.

The LPC program doesn't have any problems, I checked already with the serial bluetooth app and when you send the 'a' char it sends the 0900,1030,1120,1450 string correctly, it's a problem from the app.

The delimiterbyte is 0 and the pollingrate is 10, if it helps (I haven't touched them)

Thanks in advance and sorry if I didn't use the forum correctly, I'm kinda in a rush :sweat_smile:

Be sure to use println() at the end of each message to send from the sending device, to signal end of message.

Only use print() in the middle of a message.

Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.

Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Some people send temperature and humidity in separate messages with distinctive prefixes like "t:" (for temperature) and "h:" (for humidity).
(That's YAML format.)

The AI2 Charts component can recognize these and graph them. See Bluetooth Client Polling Rate - #12 by ABG

To receive YAML format messages, test if the incoming message contains ':' . If true, split it at ':' into a list variable, and find the prefix in item 1 and the value in item 2.

Here is an updated blocks sample illustrating these ideas ...

BlueTooth_delimiter_sample.aia (3.4 KB) global message