Receiving Data in different text boxes

Hi I was wondering if you could help me with my app. Basically I am trying to send data from the Arduino (which is connected to a flow sensor and load cell) to an app I created. The flow sensor is used to measure the amount of urine in a urine bag. I am using a RGB led to indicate how full the urine bag is. For instance, if its 25% full the greed LED will be ON, 50% full = blue LED will be on and 75% = red LED will be on. So the app will display the level of urine in the bag and the state of the RGB led. However when I try to display the data on the app all the data is clumped into 1 box and I cant separate it into different boxes. I have inserted a picture of my app building blocks layout and my arduino code. It would be great if you could help me thank you very much

![Screenshot (163)|690x388]

In the blocks, Gtext stands for the text box for Green LED same for Btext and Rtext.

This is my arduino code

This thread appeared in the private mail section of this board addressed to me.

While I appreciate the vote of confidence, the thread would be better served by the community as a whole, so I am reclassifying it as a public thread, so more eyes can move it along.

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.

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.

Please export your project and post it here.

A screenshot of code is useless, like a photo of a closed book.

1 Like

Thank you very much for the prompt reply, really appreciate it. I will try the suggested solutions

Receive.aia (522.4 KB)

i have already a clock timer used in my app , should i use a different clock for send and recceive?

If any of:

  • the clock frequencies are different,
  • if one is single shot versus repeating,
  • if Timer event processing requirements are different,

then use separate well named clocks.