issue while using loop in side a void loop

hi

here i'm using a nodemcu module to communicate with pc using software serial,. first i'm sending string "esp8266" to pc and conforming it on pc then sending 'ok' to module ,when conformed form pc and received string 'ok' then the while loop has to be stop to send string "esp8266" then has to stay in listining mood

can any one tell me to stop whileloop in side void loop after conformation detected to pc

void loop() { int stooploop=false; while(!stooploop){ mySerial.write("esp8266"); delay(1000); if(mySerial.available()) { hostdata=mySerial.readString(); conformdata="ok"; if(hostdata==conformdata){ Serial.print("\n "); Serial.print("conformationdetected"); stooploop=true; //goto todo; } else{ break; } }else{ Serial.print("\n"); Serial.print("conformation was not detected from pc...OK ..."); }

} if(mySerial.available()){ int num=mySerial.read(); //Serial.print(num); switch (num) { case 49: { //Serial.print(ESP.getSdkVersion()); String sdkversion=ESP.getSdkVersion(); // Serial.print(sdkversion); mySerial.print(sdkversion); } and so oonnnn } } } }

VarshithTokala:
can any one tell me to stop whileloop in side void loop after conformation detected to pc

Don't use WHILE. Instead use IF and allow loop() to do the repetition with a suitable variable to keep track of the state of the system.

Don't have the same code (such as Serial.read() ) in several different places. Just have a single function to get all the serial data. Repeating code just makes for more typing and more errors.

DON'T use GOTO - ever. (It is only for experts, and they know not to use it)

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code looks like this and is easy to copy to a text editor. See How to use the Forum

...R

  int stooploop=false;
  while(!stooploop){

Why are you wasting memory using an int as a boolean?

  mySerial.write("esp8266");

Do you REALLY have a mySerial connected to the Arduino? If not, that is a dumb name for the instance.

If you do, what do you expect it to do with that string?

      hostdata=mySerial.readString();
      conformdata="ok";
      if(hostdata==conformdata){

Does your mySerial device respond with "ok"? Or does it respond with "OK"?

      if(hostdata==conformdata){
        Serial.print("\n ");
        Serial.print("conformationdetected");
        stooploop=true;
        //goto todo;
        }
        else{
        break;
        }

If you get "ok", end the while loop. Otherwise, jump out of the while loop. Hmmm...