Sensor Data To Thingspeak

Good day community.
I've got a software serial connection between ESP8266-E01 and an arduino Uno. Im trying to send sensor data to Thingspeak, but it looks like i have an issue with my code. I can't seem to figure it out

#include <SoftwareSerial.h>
SoftwareSerial espSerial =  SoftwareSerial(8,7);


String apiKey = "3HMMHUPRIDCED45G";
String ssid="Connectify-LTE";    // Wifi network SSID
String password ="megabone";  // Wifi network password


 // defines pins numbers
    const int trigPin = 13;
    const int echoPin = 12;
    // defines variables
    long duration;
    int distance;

   
 void setup() {
    pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
    pinMode(echoPin, INPUT); // Sets the echoPin as an Input
    Serial.begin(115200);
    espSerial.begin(115200);

   // espSerial.println("AT+CWMODE=3");
  //delay(1000);

 // espSerial.println("AT+RST");
  delay(3000);

  espSerial.println("AT+CWJAP=\""+ssid+"\",\""+password+"\"");
  delay(3000);
 }
   
     void loop(){
       digitalWrite(trigPin, LOW);
    delayMicroseconds(1000);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(trigPin, LOW);
    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
    distance= duration*0.017;
    // Prints the distance on the Serial Monitor
    Serial.print("Distance: ");
    Serial.println(distance);
    Send2Pachube();

    delay(3000);
    if (espSerial.available())
    Serial.write(espSerial.read());
}
     void Send2Pachube()
{
  espSerial.println("AT");
  delay(1000);

  
  


  

  ShowSerialData();

  espSerial.println("AT+CIFSR");
  delay(1000);

  ShowSerialData();

  espSerial.println("AT+CIPSTART=\"TCP\",\"184.106.153.149\",\"80\"");
  delay(6000);

  ShowSerialData();

   espSerial.println("AT+CIPSEND");
   delay(6000);

   ShowSerialData();

   String str="GET /update?api_key=3HMMHUPRIDCED45G&field1=" + String(distance);
   str += "\r\n\r\n";
  espSerial.println(str);
  delay(4000);
  ShowSerialData();

  espSerial.println((char)26);//sending
  delay(5000);//waitting for reply, important! the time is base on the condition of internet 
  espSerial.println();

  
  ShowSerialData();
 
  espSerial.println("AT+CIPCLOSE");//close the connection
  delay(100);
  ShowSerialData();
  delay(16000);
} 
void ShowSerialData()
{
  while(espSerial.available()!=0)
    Serial.write(espSerial.read());
}

Any1?

but it looks like i have an issue with my code. I can't seem to figure it out

Don't you think you'd get more help if you told us WHAT the issue was?

PaulS:
Don't you think you'd get more help if you told us WHAT the issue was?

my thingspeak channel isnt updating. i get a busy response in the serial monitor after this line

String str="GET /update?api_key=3HMMHUPRIDCED45G&field1=" + String(distance);

i get a busy response in the serial monitor after this line

That is nonsense. Useless creating a String variable does NOT cause a "busy response in the serial monitor".

    delayMicroseconds(1000);
    // Sets the trigPin on HIGH state for 10 micro seconds

That is NOT what the code is doing. Delaying for that long is NOT how to read a ping sensor.

NOWHERE in your code do you appear to care what the device's response to an AT command was.

Serial, including talking to the ESP, is asynchronous. You send it data. Maybe it responds immediately. Maybe (almost certainly) it doesn't.

Serial data arrives. Maybe it's the response from the last command. Maybe it isn't.

If you are going to try to force the process to be synchronous (send a command, wait for a response), then you need to NOT send another command until you have finished getting the response to the previous command AND that response was OK.

PaulS:
That is nonsense. Useless creating a String variable does NOT cause a "busy response in the serial monitor".

    delayMicroseconds(1000);

// Sets the trigPin on HIGH state for 10 micro seconds



That is NOT what the code is doing. Delaying for that long is NOT how to read a ping sensor.

NOWHERE in your code do you appear to care what the device's response to an AT command was.

Serial, including talking to the ESP, is asynchronous. You send it data. Maybe it responds immediately. Maybe (almost certainly) it doesn't.

Serial data arrives. Maybe it's the response from the last command. Maybe it isn't.

If you are going to try to force the process to be synchronous (send a command, wait for a response), then you need to NOT send another command until you have finished getting the response to the previous command AND that response was OK.

Alright, i will try it with switch statement