Program got paused at serial.raedstring function

usnig readString working but , program got pause wherever no string available on Serial .it only resume

String data="";


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

}

void loop() {
top:
  if Serial.available()>0{//-------fisrt funtion it must run when data available on RX
  Serial.println("Data recived from web it "):
  data=Serial.readString();
 if( Serial.readString()==NULL)goto top;
  if(data.length();==23){
    println("fist weigtment got ");
   //in my main programm is send data on web server 
    }
    
  if(data.length();==33){
    println("Second weigtment got ");
   //in my main programm is send data on web server 
    }
    goto top;
    
    }

    if(! Serial.available()){//------this funtion must not work if any data avilable on RX
     println("Doing less impoortant work "); 
    }
    
    }

Really, a goto statement in 2021?

sir , solution ????????????

'while' or 'do-while'. You might have to re-structure your code so it makes sense... I'm not going to do the dirty work though. It's your hole, you can dig yourself out of it.

One thing I can help you with, if you can describe the program logic step by step in plain language, I and others can help you code it from scratch.

There is so much wrong with the code provided, did you even try compiling it ?
When you do get it to compile, you’ll have to start figuring out the runtime errors.

We like to help people that try, but correcting code that has no chance of working is lost time.

i am reading string using this program properly working . but some time there was use less data available on serial and this time program got paused at Seria.readString();

My condolences. Check the documentation for readString(). It probably has a timeout.

The function terminates if it times out (see setTimeout()).

Maybe this will do what you want. At least it doesn't have all the errors in your original sketch.

String data;

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

void loop()
{
  data = "";
  
  if (Serial.available()) //-------first funtion it must run when data available on RX
  {
    Serial.println("Data recived from web it ");
    data = Serial.readString();
  }

  if (data.length() == 23)
  {
    Serial.println("first weigtment got ");
    //in my main programm is send data on web server
  }

  if (data.length() == 33)
  {
    Serial.println("Second weigtment got ");
    //in my main programm is send data on web server
  }

  Serial.println("Doing less impoortant work ");
}

this is not workign.

Well, since you aren't sharing any details with us I guess you'll just need to figure out how to make it work on your own.

You know what you are receiving, we don't. How do you know how much data will be received? If there is an endmarker, read until the endmarker.

What is the source that sends data to the Arduino/ESP8266 over serial?

It works exactly as designed. While waiting for input it displays the line "Doing less important work" over and over.

When I send it 23 characters it displays:

Data recived from web it
first weigtment got

If I send it 33 characters it displays:

Data recived from web it
Second weigtment got

If I send it any other number of characters it displays:

Data recived from web it

Sir am taking data from web_it (make from nuvaton controller) on stand by mode it send garbage data (on RX of my controller) continually . due to this i got
"Data received from web it " .
i want- if no useful data come on RX -----"Doing less important work" this should be done at this time. this is my actual problem
thanks for support.

In that case, you need to parse the input to identify valid input, so that you can reject the garbage data. As long as your code contains 'goto' statements, 99% of all C programmers will refuse to even look at it. It usually obfuscates the logic and sometimes even the purpose of the program. So please re-write it without using goto statements, and re-post.

You have both your original program, and a sample re-write to use. That should be enough to put together a creditable attempt.

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