\r is not working. What is the equivalent in app inventor?

435 views
Skip to first unread message

Mburu Mbugua

unread,
Mar 14, 2016, 6:43:44 AM3/14/16
to MIT App Inventor Forum
I want to use carriage return to split text received from a Bluetooth device. I have tried \r and it is not working.  \n is recognized.  Kindly assist.

Ghica

unread,
Mar 14, 2016, 10:23:25 AM3/14/16
to MIT App Inventor Forum
Try \n
Cheers, Ghica.

Abraham Getzler

unread,
Mar 14, 2016, 12:39:44 PM3/14/16
to MIT App Inventor Forum
\n is Line Feed (LF), which is easy to send from Arduino using println().

If you have no control over the transmitter, and must split at CR carriage return,
you can specify a delimiter of the decimal equivalent of CR = 13 in the Bluetooth client Designer component.
If you do that, and if you request -1 as your number of bytes in a ReadText, you will get just one message at a time,
with CR as the message delimiter.

ABG

Mburu Mbugua

unread,
Mar 15, 2016, 6:18:58 AM3/15/16
to MIT App Inventor Forum
Thank you very much Abraham. Specifying the delimiter in the Bluetooth client partially solved the problem.  If I want to split using the CR how can I do it?  I am asking this because some of the devices are sending the data in the format  STRING1crSTRING2cr (cr=carriage return).  If I use the delimeter I wll not pick STRING2 which is the one I need. Kindly assist further. I have tried splitting using \r but it is not working.

Abraham Getzler

unread,
Mar 15, 2016, 11:39:18 AM3/15/16
to MIT App Inventor Forum
Are you required to receive the strings two at a time, like temperature and humidity, or are the two strings
just the same reading in two messages?

If the message really is only one string at a time, twice, then request -1 bytes to get only one string at a time.

According to the ascii table CR is hex 0D.

See attached for hexify, a block that will create an Ai2 text value of CR :
It uses one of the Web component blocks for the conversion
(no web access needed.)

Split at (incoming_text, hexify("0D"))  will split incoming message into a list of strings at each \r.
Use SELECT ITEM n from LIST to get each part afterwards until length of list.

Show us your blocks and BTClient Designer settings if this does not work for you,
along with right-click-DoIt values of the incoming data stream.

ABG


hexify.aia
hexify.png
Reply all
Reply to author
Forward
0 new messages