How do I differentciate Data (Bluetooth)?

Hello, I have a small project where i recive x/y coordinates from an ESP32 via Bluetooth. My mission is to display x and y coordinates on an App (two labels?). What blocks do I need to use and how can i differentciate, which coordinate is which, because when I use this Block:


just random numbers appear and it doesnt make much sense.

thanks in advance :slight_smile:

Upload the script that is sending the coordinates, so we can match their data types.

wym the script?
The ESP Code? We are sending two decimal numbers, for example x = 13 and y = 20

Yes, that is needed to debug.

As a rule, we do not deal with code for Arduino or ESP, apart from minor corrections. Therefore, you must show your ready code for esp for which we can adapt the blocks or make minor corrections.


this is the code i am using and this is what i get in the serial monitor:
image

I dont really have an Code for the App inventor, just this block where i am recieving random numbers whenever i press the button (the button is here to display what he recieves when i press it)
image

Another issue i am facing is: I dont know how to differenciate x and y in MIT APP inventor (which blocks do i use, how is the code?)
it should apprear like this for example (in the app):

tysm in advance :slight_smile:

ReceiveSigned1ByteNumber will not properly receive data sent using a println() command.

You need to receive text, and to use a text Delimiter.
You also need to do extra SerialBT.print("x=")
and SerialBT.print("y=") right before sending your x and y to label them in the BT data stream, like you do for your Serial data stream.

Once each message arrives into a variable in AI2, test if it contains "x=" or 'y=" to decide which Label.Text to drop it into.

General Delimiter advice:
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.

...

okay i will try it and let u know if it works

tysm <3


What blocks do i need to use in order to do so?
image

First show how you changed the sketch to include the extra text.

AI2 needs to know what will be arriving.

This is my ESP Code:


image

And this is my Block in MIT App Inventor:

i tried it out and i am not recieving anything :frowning:

Show how you set the Delimiter to 10


u mean this? Already did that before trying out

1 Like

Also pull in a third label to catch unidentifiable messages

Oops, missed this.

Sometimes your eyes see what they expect to see, not what is actually there.
54b286a609631dedac955787549d8996720db493_2_690x388

Probably you have already solved by using the correction suggested by @abg,
and probably it's just a visualization mattern of your ESp code, but (in your ESP code) where is the #include "BluetoothSerial.h" line ?
Does the ESp32 code compile without errors ?