Difference between blocks at receive text from bluetooth

Hello my friends. I am having a problem with the reception of a text from bluetooth and i am trying to figure out what it is happening.... Could someone please explain me the difference of the following blocks?
I think i know of the first one, but please correct me if i am wrong....
I use a delimeter byte and when it reaches this byte it assumes that the reception has reached the end.
Am i correct?
For the second one i dont know anything

Regards Panagiotis

When you send a character to the connected device for example A as 65 you send one byte. And Bytes Available To Receive shows you the number of bytes remaining or bytes sent by the opposite device which are still not read.

I am sorry but i cant understand your example.... Lets make a hypothesis... Lets say that we send the word HELLO what happens on these two kind of reception technics? will both fill the variable? and what happens if we re-send the word HELLO ? Does this variable updates....or holds HELLOHELLO ?

Thank you very much!!!

Let's say the device you have is client-side connection. I send you a text message called "Hello". I will not get it back but/and reaches you. I send another message called "Hi", this time you still did not read the pending bytes or text. So the data should get append, that means the data pending is "Hello" + "Hi" = "HelloHi".

In the second case, only the data that is in the buffer at the moment will be received.

1 Like

On which case of the above applies?

Sorry, I don't understand?

What you explained me before..... does this applies on both blocks that i have posted on my first post?

1 Like

I am a bit confused. You're talking about receiving data and not sending...?

Ok i am sorry maybe its my fault... lets start over....
I have a sensor which sends temperarure values in this format.....

  1. What will you receive on the first block and what on the second one?
  2. What happens when new data arrive?
  3. How will these blocks understand that we have reached a complete reception so to update the variable with new data?

Thank you very much

The block which is ReceiveText(NUMBER_HERE) receives some part of the data. Let's say you have the block below.


Someone has sent you the value 26.3/30.4 then only the number of bytes mentioned in the above block will be received. So you should get the value 26 as the first 2 bytes.

In the second block, you receive the whole available bytes or data.

Note: I have never worked with the Bluetooth component.

Thank you very much for your answer.....

so in a new data arrival will update the previous one or wil have 26.3/30.4 28.8/31.2 ???

Some person sends data of value 26.3/30.4. Still, you have not used the below blocks

then the data will get append or added like "26.3/30.4" is the first value. The person sends another data again like "28.8/31.2". Here you have not used the blocks so when you use the block after the person send data two times then you should get the data "26.3/30.4 28.8/31.2".

Let's say still the person has not sent the second data. "28.8/31.2" value is still waiting to be received. When you receive it completely, there will be no data left so it becomes empty. Next times he sends the second value then the process will repeat.

I hope I have not made the post confusing :sweat_smile:.

Here is the standard boiler plate advice for BlueTooth Delimiters ...

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:

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.

really nice explanation!!! The thing that i dont really like with this reception technique is that if the microcontroller stucks and doesn't send the delimeter byte the program of the mit appinventor also stucks and waits for this particular byte, so to continue...But if a certain amount of time passes...then the companion crashes.... Do you mind if i post my aia file to explain what is happening wrong and if you can help me solve it out??


Please export your project and post it here.

Ok please read this first before reading the blocks so to understand whats happening..
I use 2 ds18b20 sensors with a pic microcontroller.
When everything is on the first run , then you have to add the sensors to the pic microcontroller. One sensor will be used in the input and the other one on the output. When you press the button to add a sensor to the microcontroller then the app sends '*' and waits 'Con_OK' when this is done then you select position of the sensor (in or out) and when it has finished the registration then the microcontroller sends 'Reg_OK' to inform the app that it was a successfull registration.
After that on every 3 seconds the app sends '?' to to inform the microcontroller that request the temperature and the microcontroller sends it in a format of 25.5/30.2
So far so good.... and everything works as expected.....
The problem arises when you want to add a new sensor...
Then it runs the add sensor timer but although the microcontroller sends the text 'Con_OK' it runs the else part which is that the connection has failed.
But after that it appears on the main screen which makes me believe that the buffer does not empty.

Thank you all for your concern Panagiotis

Sup_Sup_Monitor_One_Screen2.aia (97.0 KB)

ps. I have also used the bytes available to receive with same results

I see three Clock Timers, working at cross purposes ...

This connection timer is presumptuous, assuming instantly available input, with a guaranteed '/'. It also fails to check if input is available, before asking for input and blocking if none available.

I would only use this timer to send the '?' polls, and only if connected.

This timer also fails to check if input is available before asking for it, also potentially blocking.
It also assumes it will only ever receive 'Reg_Ok', and discards anything else, like /-delimitted readings.

This also is like the Reg_Ok timer, but with Con_Ok.

Consider consolidating all 3 timers into one timer, responding to input by content:

global message

In the process routine, put a three way if/then/elseif test to respond appropriately to

  • Reg_Ok
  • Con_Ok
  • a message with '/' in it (text CONTAINS block).

You are awesome!!!! Really appreciate it!!! I will try it out and and post my results. But unfortunately i cannot find these 2 blocks at mit appinventor...

And what is your proposal for the interval period of this clock? 100mSec?
Also i cannot get rid of the other clock since i need on every 3 secs, the app to request the temperarute from the microcontroller sending the ? character