I would like to send numerical data from a mobile to my device via Bluetooth (BLE).
For example, I want to send the number 31111. To do it, I convert each single digit to its corresponding ASCII value (3 is 51 and 1 is 49) and send it byte by byte. I did this only for test, because this method is not very optimal, but it proved that my device can read data from the app. Below the picture to better understand what I did.
In the final version of my app, I want to have a text box where the user can enter a random number.
My question is, how can I convert the data from the text box and send it to my device in a more efficient way than using multiple writeBytes blocks one by one?
The values parameter has a name ending in 's', to imply that it can accept a list.
(Double check me by consulting the block's tool tip.)
So you could send a list of bytes.
But why not just send a text string using the block for that?
And shouldn't there be consideration of how to know at the other end that it has seen the end of the text, through some ending character ('\n' or '\0') or by some BLE protocol in the Text transmission block?
I solved my problem, but I did it by not very smart way. I am pretty sure that it could be done much easier.
The root problem is I want to convert text from text box to number in dec and next convert it to ASCII
For example: "1" (text) -> 1 (dec number) -> 49 (dec number from ASCII table)
Below you can find my code. It is working ok, but I have to optimize it. I am wonder if Mit App Inventor has a dedicated tool or function to do it.
I try to explain my code. First I read 4 digits number from the text box. Next I divide this text to single char and convert each single char to number. At the end number is converted to ASCII number. I used a lot of "if instruction" to make it.