Problem about ESP8266 self UART communication

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX

void setup()
{
  Serial.begin(115200); 
  ESPserial.begin(9600);
  Serial.println("initial ready");
}

void loop() {
  while(Serial.available()>0){
    Serial.println("available");
    
    if(ESPserial.available()){
    Serial.println("ESP written");
    ESPserial.write("A");
    }
    delay(1000);
    Serial.println( ESPserial.read());
  }

}

So, here is my code, and I’m totally new in arduino.
Pin 2 and 3 are connected with each other.
I supposed ESPserial.read should get the char “A”, but it’s not. And ESPserial.available can never be reached.
I want esp to communicate with itself, so that I can check the output and input functions of this chip are working properly. Later I will connect it to another micro controller, so it’s important to make this part to work.
If there is anything I missed? Thank you guys…

fisherxx:

#include <ESP8266WiFi.h>

#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX

void setup()
{
  Serial.begin(115200);
  ESPserial.begin(9600);
  Serial.println(“initial ready”);
}

void loop() {
  while(Serial.available()>0){
    Serial.println(“available”);
   
    if(ESPserial.available()){
    Serial.println(“ESP written”);
    ESPserial.write(“A”);
    }
    delay(1000);
    Serial.println( ESPserial.read());
  }

}




So, here is my code, and I'm totally new in arduino. 
Pin 2 and 3 are connected with each other.
I supposed ESPserial.read should get the char "A", but it's not. And ESPserial.available can never be reached. 
I want esp to communicate with itself, so that I can check the output and input functions of this chip are working properly. Later I will connect it to another micro controller, so it's important to make this part to work. 
If there is anything I missed? Thank you guys...

It will never enter the while loop unless something is received on the serial input. You would have to be typing in the serial monitor for it to enter the while loop. If it does enter the while loop it will never write to ESPserial unless something is available on the ESPserial. If nothing is available on ESPserial you don’t write to it but still try to read from it after a 1 second delay…even though nothing was written to it. This all seems confusing and backwards to me.

That while() loop only functions if anything is available on the Serial port. If nothing is present, you never get to the rest of your code which does the ESP send/receive. Are you sure that's the logic you desire?