Process a received data by bluetooth

Hi everyone
I want to do a very simple thing: When the data received by Bluetooth is 1, show the message "connected" and when it is 0, show the message "not connected". I´m very new to the App Inventor. I don´t have any problem receiving data but I don´t know how to use the conditional blocks to process the received data.

Hello Jaleh

Assuming your connected/not connected message is not an attempt to report the status of the Bluetooth connection, you can use code like this:

blocks

Hi,
Thank you so much for your response. I have various characteristics associated to my Bluetooth service. The last characteristic in the image of my blocks is the one which I want to check if it´s 0 or 1.

If you want to test byteValues for 0 or 1, you have to do it in a foreach loop, byte by byte:

for each byte in byteList
  if byte = 0 then
    do this
  else if byte = 1 then
    do that
  else
    complain about byte

This is necessary because BLE ByteList is a list, even though it might have only one byte in it, and any attempt to do a math or text operation against a list causes AI2 to convert the list into a text value of the form "[a,b,c,...]", wrapping it with [] to annoy you into respecting list blocks.

1 Like

It works, thank you!

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