I am trying to have the app display the temperature with a DHT11 but this message keeps popping up whenever I open the app and connect to my HC-05. I provided a screenshot of the message and blocks bellow, I would greatly appreciate any help on how to fix this!
According to the error message, the incoming message said "Sent", which is not a number you could compare withanother number like 35.
Get whoever wrote the sketch to upload their code to this thread.
And maybe have them show it to you too?
Here is some stock advice on message delimiters, which you also need:
Here is a simple BlueTooth text receiver sample, for single value per line:
when Clock1 .Timer do1290×410 59.1 KB
when Screen1 .Initialize do814×182 22.9 KB
..
Notice the -1 in the text receive block, and the setting of the BT Delimiter byte to 10 (Line Feed)
Long winded version:
Be sure to use println() at the end of each message to send from the sending device, to signal end of message.
Only use print() in the middle of a message.
Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.
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.
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.
Some people send temperature and humidity in separate messages with distinctive prefixes like "t:" (for temperature) and "h:" (for humidity).
(That's YAML format.)
The AI2 Charts component can recognize these and graph them. See Bluetooth Client Polling Rate - #12 by ABG
To receive YAML format messages, test if the incoming message contains ':' . If true, split it at ':' into a list variable, and find the prefix in item 1 and the value in item 2.
HI! Thank you so much for your response! I am still very new to MIT app inventor, as this is my first project, so I struggled a bit with understanding the steps I should take. I attached the code file to this message. I deeply apologise but I did not really have good comprehension on what to do. ![]()
temp.aia (135.8 KB)
I am on jury duty today, so I might be a while
(Guillotine!)
You are using local variables, whch is great, but to be able to debug, use a global variable list instead and display it in a label to find out what you received.
Then depending on that, adjust your blocks accordingly.
Generally use the companion app and Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools
Taifun
Hi! Thank you so much. I solved the problem and is now running smoothly. I appreciate both of your responses!
Might help others if you tell us what you did to solve the problem.





