really nice explanation!!! The thing that i dont really like with this reception technique is that if the microcontroller stucks and doesn't send the delimeter byte the program of the mit appinventor also stucks and waits for this particular byte, so to continue...But if a certain amount of time passes...then the companion crashes.... Do you mind if i post my aia file to explain what is happening wrong and if you can help me solve it out??
Ok please read this first before reading the blocks so to understand whats happening..
I use 2 ds18b20 sensors with a pic microcontroller.
When everything is on the first run , then you have to add the sensors to the pic microcontroller. One sensor will be used in the input and the other one on the output. When you press the button to add a sensor to the microcontroller then the app sends '*' and waits 'Con_OK' when this is done then you select position of the sensor (in or out) and when it has finished the registration then the microcontroller sends 'Reg_OK' to inform the app that it was a successfull registration.
After that on every 3 seconds the app sends '?' to to inform the microcontroller that request the temperature and the microcontroller sends it in a format of 25.5/30.2
So far so good.... and everything works as expected.....
The problem arises when you want to add a new sensor...
Then it runs the add sensor timer but although the microcontroller sends the text 'Con_OK' it runs the else part which is that the connection has failed.
But after that it appears on the main screen which makes me believe that the buffer does not empty.
This connection timer is presumptuous, assuming instantly available input, with a guaranteed '/'. It also fails to check if input is available, before asking for input and blocking if none available.
I would only use this timer to send the '?' polls, and only if connected.
This timer also fails to check if input is available before asking for it, also potentially blocking.
It also assumes it will only ever receive 'Reg_Ok', and discards anything else, like /-delimitted readings.
You are awesome!!!! Really appreciate it!!! I will try it out and and post my results. But unfortunately i cannot find these 2 blocks at mit appinventor...
And what is your proposal for the interval period of this clock? 100mSec?
Also i cannot get rid of the other clock since i need on every 3 secs, the app to request the temperarute from the microcontroller sending the ? character
Thank you very much for your answer but i still cant find the first arrow i drew.... "call process message block" There isnt such a block on mit appinventor procedures tab.
****EDIT: I re-wrote the word Con_OK and now seems to work as expected!!! I am currently making tests.... Perhaps it had to do with the drag i did to your post.... Maybe some corrupted characters??? I will post the results!! Also i changed the variable from message to global message
When does the process run? When it reaches the delimeter byte?
I really cant understand the part of -1 it says..... If there is 1 or more bytes available then set the global variable to the received text... But where does the -1 assosiates?
-1 need not understand, you need to know that when we add -1 to read, then the read block stops the program and reads the bytes until it reads the delimiter byte. Next program continues and executes the procedure.
As far as i can understand you two don't say the same....
Patryk says that the procedure is run after the bluetooth has reached the delimeter byte and
Abraham says that it runs each time the timer reaches its interval period..
So to summarize.....On each time that timer's interval triggers, it runs this blocks of code, and if the reception has received the delimiter byte, it runs the process block.... Is this correct?
In fact, when using "numberOfBytes = -1" it is not necessary to use the read clock. This method is synchronous, so it will stop the program anyway until it reads all the text into delimiterByte. There will be no merging of the received text here so you can use the normal procedure instead of the clock. The clock is only needed to read the text cyclically.
Whether your device sends something once or cyclically? I think it has already been said so much that now for your full understanding it will be necessary to test on a real bluetooth device and tests with receiving messages. It is best to learn by making examples and testing on your own skin.