(apologies if this is in wrong forum section, happy to be redirected if need be, as long as I don;t have to enter it all again!)
I have an Arduino (a teensy 4.1) communicating over bluetooth classic with my AI2 app. The teensy is fitted with up to five DS18B20 thermometers and runs a sketch that sends a compound CSV text string containing the temperatures over bluetooth, every 2 seconds.
Here are the sketch code pieces for transmitting the string:
#include <Streaming.h>
#define bt Serial7 // Bluetooth on TX7/RX7
bt << "#" << _FLOAT(DT0_degrees,2) << ","
<< _FLOAT(DT1_degrees,2) << ","
<< _FLOAT(DT2_degrees,2) << ","
<< _FLOAT(DT3_degrees,2) << ","
<< _FLOAT(DT4_degrees,2) << '\n';
My AI2 mobile App is reading the text string but I'm having trouble parsing the string using "list from csv row".
Using the "Serial Bluetooth Terminal" on my mobile shows the CSV strings are being sent correctly
A reading of -99.00 means that thermometer is not connected yet. Each string is preceded by a hash character (#).
The longest string (no thermometers connected) would be #,-99.00,-99.00,-99.00,-99.00,-99.00
for a total length of 1 + (5 x 7) + 1 = 37 characters including the \n line feed.
The shortest string (all thermometers active) would be
#,00.00,00.00,00.00,00.00,00.00
for a length of 1 + (5 x 6) + 1 = 32 characters.
In testing I noticed that reception of the whole string by bluetoothClient is inconsistent. Sometimes it receives a few bytes, sometimes 1 byte, but most times it receives the whole string correctly. To handle this I added the extra test to redirect any dud strings into dummyString (also ensures the Serial buffer is emptied)
If BytesAvailableToReceive > 30
load into textString (& lbl_String)
else
load into dummyString
But when I run the App using AI Companion I get this runtime error:
If build and load the App onto my mobile I get this similar error:
Here are my parsing blocks:
- How can I avoid these bugs ?
In addition my attempts to parse and display the individual temperatures on the App screen is not working as shown in this screenshot:
Note the display does show lbl_byteCount, lbl_String values (yellow arrangement) showing current textString and byte count to help in debugging.
- How can I get the parsing to work so values appear on screen?
In case they are important, here are the blocks for whole App:
A couple of other minor Q's if I may:
-
Is it possible to strip the \n character of end of textString before displaying in lbl_String (so it doesn't wap on the App screen)?
-
why does my tick counter trigger every 10ms even though the setting in TimerInterval for Clock1 is set at 500ms?
Many TIA