How to receive long serial data bytes(31 bytes) through Bluetooth module

Microcontroller is transmitting 31 bytes of data (BaudRate of 9600). But I'm not able to receive complete 31 bytes. I have to split(by ";") and process those 31 bytes at a stretch. But I can't!!.. Here I'm attaching my App blocks. Some error has thrown as " Attempt to get item number 7 of a list length 1:". Because I'm not getting complete 31 bytes at a stretch.

31 byte serial data from controller: (Separated by commas)
0;2;0;0;2;0;0;1536;1542;1.49;5967;7.27;21.33;8;21;50;30;31;1432;-1787;19372;-4353;1892;-197;352;268;19274;-4414;4;0;1.4kW;

See this topic. There was less data there, but do the same.

1 Like

what's the purpose of Delimeter byte? I set DelimeterByte to 31, I'm not receiving any bytes

Ideally, you should show your arduino code. When you send the last message to the command "serial.println ()", a line break (10) will appear at the end of the message. Then the application will receive all data up to the character 10. You can separate individual bytes with the | character. You will then use a split block and make a list with your bytes. Managing your list is now easy. Of course, follow the information and set 10 in DelimiterByte.

len = sprintf(buffer,"$%x;%x;%x;%x;%x;%i;%i;%i;%.2f;%i;%.2f;%.2f;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%x;%x;1.4kW;\r\n", data1, data2, data3, data4, data5, data6, data6, data7,data8, data9, data10, data12, data13, data14, data15, data16, data17,data18, data19, data20, data21,data22,data23,data24,data25,data26,data27,data28,data29,data30,data31);

HAL_UART_Transmit(&huart3, buffer, len, 100);

This is my controller data.
Yes, I'm including new line "\n" after each 31 byte transmission [$ is my start of text, 1.4kW is my End of text], highlighted bold!

So set DelimiterByte to 10. See what you received. You can remove the $ sign because in blocks you will have to get rid of it anyway. You can also remove the \r mark.

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. 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.