Receive whole string in serial sending data? I connect my NodeMCU to Arduino Uno. The goal is to receive the whole string for example "12", every 1 sec.

This is my code on Arduino Uno side ( the sender) 

int mock = 0;

void setup() {
  Serial.begin(115200);
  s.begin(115200);
}

void loop() {
    //Write mock to NodeMCU
    s.print((int)mock,DEC);
    s.println();

    mock++;
    delay(1000);
}


On NodeMCU side ( the receiver) 

 char data; //Initialized variable to store recieved data
 String line;
 void setup() {
   Serial.begin(115200);
   s.begin(115200);
   while (!Serial) {
    ; 
  }
}

void loop() {

    if( s.available() &gt;= 2) {
        for (int i = 0; i&lt; 2; i++ ) {
            data = s.read();
            line += data;
        }
        delay(1000);
    }


    Serial.print(line);

}


But the result on the serial panel is not what I expected


How can I make it so that I can receive something like

12
(wait one sec)
13
(wait one sec)
....


Node MCU just prints the whole thing, I can't delay it.
If you send "12" you send 4 characters/bytes: '1', '2' and a new line which is two characters:  ('\r', '\n').

On the receiver side you check for two characters (not the new line), so you should take it into account.

Actually, since you will eventually reach "100" you will receive 5 characters ('1', '0', '0', '\r', \'n').

So it is better to change the receiver side to store the bytes in line UNTIL a new line is received (than you can support values of any length).

Also remove the delay on the receiver side, or at least decrease it a lot, because it doesn't matter to check (too) often. if there is no byte available, it will check again. Now it can happen at time 1001 ms a byte would be received, but at time 1000 ms it is checked and it will not be checked again until time 2000 ms.