I do not quite know if your code makes sense to me.
- There is a chance that
String data1 = Serial.readString();
just reads one or two bytes. -
while (Serial.available()) Serial.read();
throws anything away that might be useful. -
while (Serial.read() >= 0) ;
does the same as (2)
I suggest that you study Serial Input Basics - updated to get some ideas for your serial communication.