Getting inputs from arduino/ and saving bluetooth mac address to use later

hey. I'm currently developing an app to aid blind people after trying a couple of different things I couldn't get it to work.
This is how I tried to make it work 1st it tests if bytes available to receive are bigger than 0 otherwise it would just crash. (this doesn't work tho). could someone give me some way to do this?
this is the Arduino code:
arduino.txt (4.4 KB)
I need to constantly check the output of the Arduino since it tells me where the obstacles are.
I can't get the save mac address to work either, if anyone knows how to do this I would be very thankful for your help.


I see from your sketch you are transmitting your data like this:

 Serial1.println("1");

On the AI2 side, you would receive this as text data and use a Line Feed Delimiter = 10 in your BlueTooth component Delimiter value.

Also, you should only do a single BlueTooth.ReceiveText(-1) and send its output into a global variable MESSAGE, then do all your tests against the contents of global MESSAGE, to avoid flushing your input with too many Reads.

Standard AI2 Delimiter advice:

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.

1 Like

thanks, it worked :slight_smile:
could you tell me how to make these slider numbers be just integers instead of floats I know how to do it in the Arduino but it may cause confusion on the assistant view, I'm using this so that the blind's assistant can select his height since it's an important factor. also, could you do an example of how would it look to save the Bluetooth mac address only and not the name
image

Split the string/number at "." (the decimal point) and select the first item in that split list.

1 Like

didn't work now it show's example: ["145", "89999"]
what would it look like on blocks?

To get an integer from a float, pass it through the math block 'round'.

1 Like

Select the first item using "select list item" in Lists. The list is that split list you said just now, and the index is 1.

1 Like

thanks guys

How can I save the mac address tho?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.