Communication between NodeMCU esp8266 and Arduino Mega 2560

Hi guys
I have been trying to set serial communication between NodeMCU ESP8266 and Arduino Mega 2560(clone).
I found out how to do that on this website: https://create.arduino.cc/projecthub/pawan-kumar3/serial-communication-between-nodemcu-and-arduino-640819.

But i wanted it in reverse so ESP will send something to arduino and when arduino will receive something, it puts that into some variable and then for example turn on a led.

But I have one trouble. I cannot convert received text from serial into any variable cause it only displays 1 or some wierd characters.
Can somebody help me with this?

Here is code for ESP8266:

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

void loop() { 

  Serial.println('1');
  delay(1000);
  Serial.println('2');
  delay(1000);

}

And here is Arduino code:

void setup(){
  pinMode(13, OUTPUT);
 Serial.begin(115200);
 Serial1.begin(115200);
/*while (!Serial1) {
    ; // wait for serial port to connect. Needed for native USB port only
  }*/
}
void loop()
{
  
  if (Serial1.available()) {
    Serial.write(Serial1.read());

  int str = Serial1.read();
  if(str==1){
    digitalWrite(13, HIGH);
    }
    if(str==2){
    digitalWrite(13, LOW);
    }}
    
}

On arduino i have wires on RX1, TX1, PMW port 13 with ground and one ground is directly connected to ESP
On ESP i have only RX connected to TX1 and TX to RX1 and also that ground.

Thanks for any help :slight_smile:

you send '1' and test 1

Yeah that is mistake but it is not reason why it is not working....i have tried it different times with "", '', or just in () but still doesnt work..