Please help on creating tcp connection using ESP8266 and Arduino Uno

Hi everyone, I am trying to push notification to android phone via Pushetta/PushingBox via Wifi using Arduino UNO and ESP8266-01, by creating TCP connection.
The ESP8266-01 successfully connected to Wifi but was unable to establish connection to Pushetta not PushingBox. I tried to connect to both using their IP address and server name using TCP Test Tool for testing. PushingBox’s connection never lasts more than 10 sec, while Pushetta’s connection is fine. However, when it comes to using Arduino UNO, failure occurs.
I keep getting failure messages from my serial monitor as follow:
SEND: AT
OK
- connecting to Home Router SID: gloriachu
SEND: AT+CWJAP=“gloriachu”,“0001984085235”
Wifi Loading…Wifi Loading…Wifi Loading…Wifi Loading…OK
- WiFi succesfully connected
Connecting to Pushetta
Connection failed
Connecting to Pushetta
Connection failed
Connecting to Pushetta

Hence, I doubt its a tcp connection issue. I have googled for more examples but all the references seem to be using Wificlient and client.connect(), which is the same one I am using. Hence I would be really grateful is anyone could help on solving this issue… Is it something to do with my code? Or wrong connection method applied?

Thanks!

Arduino Code:

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <SoftwareSerial.h>
/************
Pushetta_ESP8266/Pushetta_test.ino
https://github.com/Astu04/Pushetta_ESP8266/blob/master/Pushetta_test.ino
*/
#define _baudrate   9600
#define _rxpin      4
#define _txpin      5
SoftwareSerial debug( _rxpin, _txpin ); // RX, TX
//*-- IoT Information
#define SSID "gloriachu"
#define PASS "0001984085235"

// Put here your API key. It's in the dashboard
char APIKEY[] = "84e492d4faf558f7f644f26b389b5d3db0d32d99";
// and here your channel name
char CHANNEL[] = "PushNotification_1";                               
char serverName[] = "api.pushetta.com";

boolean lastConnected = false;
int status = WL_IDLE_STATUS;
//IPAddress ipMulti (192, 168, 1, 255);
boolean connectWiFi()
{
    debug.println("AT+CWMODE=1");
    Wifi_connect();
}
 void Wifi_connect()
{
    Serial.println("- connecting to Home Router SID: " + String(SSID));
    String cmd="AT+CWJAP=\"";
    cmd+=SSID;
    cmd+="\",\"";
    cmd+=PASS;
    cmd+="\"";
    sendDebug(cmd);
    Loding("Wifi_connect");
}
void Loding(String state){
    for (int timeout=0 ; timeout<10 ; timeout++)
    {
      if(debug.find("OK"))
      {
          Serial.println("OK");
          break;
      }
      else if(timeout==9){
        Serial.print( state );
        Serial.println(" fail...\nExit2");
      }
      else
      {
        Serial.print("Wifi Loading...");
        delay(500);
      }
    }
}
void sendDebug(String cmd)
{
    Serial.print("SEND: ");
    Serial.println(cmd);
    debug.println(cmd);
}  
//Function for sending the request to Pushetta
void sendToPushetta(char channel[], String text) {
  Serial.println("- starting client");
  WiFiClient client;
  Serial.println("- connecting to server: " + String(serverName));
  
  if (client.connect(serverName, 80))
  {
    Serial.println("- server succesfully connected");
    client.print("POST /api/pushes/");
    client.print(channel);
    client.println("/ HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.print("Authorization: Token ");
    client.println(APIKEY);
    client.println("Content-Type: application/json");
    client.print("Content-Length: ");
    client.println(text.length() + 46);
    client.println();
    client.print("{ \"body\" : \"");
    client.print(text);
    client.println("\", \"message_type\" : \"text/plain\" }");
    client.println();
  }
  else
  {
    client.stop();
    Serial.println("- stopping the client");
  }
}

void setup() {
  Serial.begin(_baudrate);
  debug.begin( _baudrate );
  sendDebug("AT");
  Loding("sent AT");
  connectWiFi();
  Serial.println("- WiFi succesfully connected");
}

void loop()
{
  Serial.println("Connecting to Pushetta");

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect("api.pushetta.com", httpPort)) {
    Serial.println("Connection failed");
    return;
  }
  // Sending a notification to your mobile phone
  // function takes the message as a parameter
  sendToPushetta(CHANNEL, "Hello from Arduino!");
  delay(60000);
}

The example code you found was designed to run directly on an ESP8266 which has the Arduino core ESP8266 software.

The code that you have created is running on a Uno and is talking to the ESP8266 which is running the default firmware with an AT command interpreter.

You get as far getting the UNO to make a connection to your wireless lan via the ESP8266. Your problem is, as far as I can see, is that you are then attempting to run commands on the UNO such as the following at the point it fails:

  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect("api.pushetta.com", httpPort)) {
    Serial.println("Connection failed");
    return;
  }

These are commands which you have copied from the ESP8266 code which are intended for when the UNO has native network connectivity via its own shield (Ethernet/WLan etc.). Not in the situation where you have offloaded all the networking to a remote device, in this case the ESP8266.

You could try running the example code directly on the ESP8266. If you do so, however, you will overwrite the standard ESP8266 firmware (AT command interpreter etc.) with the Arduino core software and would have to re-flash it if you want to restore this functionality. Also the ESP-01 breakout does not have many pins.

Thanks for your reply! May I ask how can I amend my code to fit in to the situation of offloading all the networking to a remote device?

As far as I see, your options are: 1. Convert the logic which you have found to AT commands as you have done with the initial connection to the wlan and continue with your present setup. 2. Run the whole sketch directly on the ESP device

I'm no expert in using AT commands so I can't say what your chances of success are with option 1.