ARDUINO data LISTS Unable TO SPLIT WORDS From NUMBERS

I'm trying to make a voltage monitoring app to measure voltages
,voltage drop, voltages differences between cells and some other tests,
problem is I cant get around to split the incoming data in the right way,
specially cause data comes with “,“ commas and “:“ colons punctuation mark in same strings,
i can be able to read all the voltages sometimes they well organize
in all the respective labels sometimes all mix up, all depends on the data flow.
But I need to read the information on top INFOMA LABEL. And the voltages on
botton rows,im kind of newbie on app inventor and followed many many many tutorials and nothing yet,
Any help would be greatly appreciated. Thanks! In advance to all of you,The aia file is attached
voltage_monitoring.aia (8.6 KB)


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.
BlueToothClient1_Properties
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.


dis
(delimiter byte value is in 10 already, that's a rule that i won't miss out.)

#include <SoftwareSerial.h>


void setup() {
  Serial.begin(9600);
}

void loop() {

  int poT1  = analogRead(A0);
  int poT2  = analogRead(A1);
  int poT3  = analogRead(A2);
  int poT4  = analogRead(A3);
  int poT5  = analogRead(A4);
  int poT6  = analogRead(A5);
  int poT7  = analogRead(A6);
  int poT8  = analogRead(A7);
  int poT9  = analogRead(A8);
  int poT10  = analogRead(A9);

  Serial.print("VOLTAGE:");
  Serial.print(poT1);
  Serial.print(",");
  Serial.print(poT2);
  Serial.print(",");
  Serial.print(poT3);
  Serial.print(",");
  Serial.print(poT4);
  Serial.print(",");
  Serial.print(poT5);
  Serial.print(",");
  Serial.print(poT6);
  Serial.print(",");
  Serial.print(poT7);
  Serial.print(",");
  Serial.print(poT8);
  Serial.print(",");
  Serial.print(poT9);
  Serial.print(",");
  Serial.print(poT10);
  Serial.print(",");
  Serial.println();

}

TRY something simple like this sketch and is not working as it should

If you control the sketch, simply don't do that print("VOLTAGE:");

Why make problems for yourself?

I see you send messages to the Arduino, but do not listen for them.

To accommodate variable length responses, you can do this:
Here is an updated blocks sample illustrating these ideas ...

BlueTooth_delimiter_sample.aia(3.4 KB) global message

...

Alternatively, consider sending individual readings as YAML format, one reading per line, and split at ':' to get label and value.

( to keep on learning. :triumph: )
but i'll try again and see if i can accomplish to separate the string with the sample code you already gave me. if not,teacher is going to fry me like americans potatoes.
thanks by the way.i appreciate your time on this ABG.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.