简体   繁体   中英

Reading data in-between symbols from Serial Arduino C

How can I find the data in between the { } symbols and store the information in a char?

I have tried the following with no joy it keeps stopping.

void loop(){
      data = Serial.read();
      if(data>0){
        recData[i] = data;
        i++;
        Serial.print(data);
      }
    }

This is the code that reads the information.

void loop(){
  data = Serial.read();
  if(data>0){
    Serial.print(data);
  }
}

OUTPUT DATA:

HTTP/1.1 200 OK
Content-Type: text/plain
Expires: Sat, 01 Feb 2014 22:06:18 GMT
Connection: close

{Read Data Inside Here}
CLOSED
String finaldata = "";
void loop()
{

    while (Serial.available()) {
        char recv = Serial.read();
        if (recv != 0x00) finaldata += recv;
        if(finaldata.indexOf('}') > 1){
            int firstBracket = finaldata.indexOf('{');
            int secondBracket = finaldata.indexOf('}');
            finaldata = finaldata.substring(firstBracket, secondBracket);
            Serial.print(finaldata);
            break;
        }
        delay (10);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM