EOL and SOL, working only first time xD

char str[25];
int i=0;
int str_len;
int inByte;
int last_inByte;
String rezultat;

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

void loop() {
  inByte = Serial.read();
  str_len=0;
  if (inByte == '!') read_serial();
}

void read_serial() {
  Serial.println ("SOL FOUND and reading");
  Serial.print("READ: !\n");
  while (inByte!= '*')
  if (Serial.available() > 0) {
    inByte = Serial.read();
    Serial.print("READ: ");
    str[str_len] = inByte;
    Serial.println(str[str_len]);
    str_len++;
  } else if (Serial.available() == 0) {
    Serial.println("EOL not available, data str invalid");
    Serial.println("$N");
    break;
  }

  if (inByte == '*') {
    Serial.println ("EOL FOUND");
    for (i=0;i<(str_len-1);i++) {
      rezultat += str[i];
    }
    if(rezultat == "YES") {
      Serial.write("Yeah");
    }
      Serial.print ("\n");
    }
}

I get 'Yeah' back only if I send !YES* as first send thing from opening serial monitor. Otherwise I don't get 'Yeah' at all. Please help.

Bump?

rezultat += str*;*
Won't this just keep getting added to with every pass? I don't see anything that resets it.
Try printing it, see if it just gets longer & longer.

It's inside for loop. It will loop only as much times as there are bytes waiting. I can print it, and everything is normal.

Anyone?

Re-read CrossRoads question and think about this. Suppose you send to the serial port this data:
!Yes*!No*!Maybe*

What will rezultat contain when the first * is encountered? "Yes".

What will rezultat contain when the next * is encountered? "YesNo"

What will rezultat contain when the next * is encountered? "YesNoMaybe"

At some point, after you use the contents of rezultat, you should reset it to an empty string.

It's you again. :slight_smile: Thank you one more time. It's finally working.

char str[25];
int i=0;
int str_len;
int inByte;
int last_inByte;
String rezultat;
int baud = 9600;

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

void loop() {
  inByte = Serial.read();
  str_len=0;
  if (inByte == '!') read_serial();
}

void read_serial() {
  Serial.println ("SOL FOUND and reading");
  Serial.print("READ: !\n");
  while (inByte!= '*')
  if (Serial.available() > 0) {
    inByte = Serial.read();
    Serial.print("READ: ");
    str[str_len] = inByte;
    Serial.println(str[str_len]);
    str_len++;
  } else if (Serial.available() == 0) {
    Serial.println("EOL not available, data string invalid");
    break;
  }

  if (inByte == '*') {
    Serial.println ("EOL FOUND");
    rezultat = "";
    for (i=0;i<(str_len-1);i++) {
      rezultat += str[i];
    }
    if(rezultat == "YES") {
      Serial.println("Yeah");
    }
      Serial.print ("\n");
    }
}