Sending post request from arduino uno using WiFiEsp library data not receiving

Greetings…

I am trying to Send a Post Request using Arduino UNO with ESP8266 WiFi module connected using WiFiESP library to web server connected to a domain but data from xml is not fetching after successful connection to the server…
I am making a project to control relays from anywhere…
i tried this code before on Ethernet shield it was working working perfectly now when i changed the code to connect it to ESP8266 it is cuasing the problem mentioned above…

This the code i am using…
Please help me getting out of this problem…

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(11, 12); // RX, TX
#endif

char ssid[] = "Tech Feast";            // your network SSID (name)
char pass[] = "saadtech12";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
////////////////////////////////////////////////////////
int devices[]={2,3,4,5,6,7,9,10};
#define MAX_STRING_LEN  20
char tagStr[MAX_STRING_LEN] = "";
char dataStr[MAX_STRING_LEN] = "";
char tmpStr[MAX_STRING_LEN] = "";
char endTag[3] = {'<', '/', '\0'};
int len;
int count=0;
boolean tagFlag = false;
boolean dataFlag = false;


///////////////////////////////////////////////////////
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

char server[] = "tech-feast.000webhostapp.com";    // web address (using DNS)
 
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
IPAddress myDns(192, 168, 0, 1);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiEspClient client;

void setup() {
    // initialize serial for debugging
  Serial.begin(115200);
  // initialize serial for ESP module
  Serial1.begin(9600);
  // initialize ESP module
  WiFi.init(&Serial1);

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  // you're connected now, so print out the data
  Serial.println("You're connected to the network");
  
  printWifiStatus();

  Serial.println();
  Serial.println("Starting connection to server...");
 


  // set output
   for(int i=0;i<10;i++)
  {
   pinMode(devices[i],OUTPUT); 
  }
  


}

void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void loop() {

 delay(3000);
 httpRequest();




}

void httpRequest() {
  Serial.println();
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  client.stop();

//int counter=0;
//int found;
//char data[]="";  
//String str;  
  
  
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("Connecting...");
    // send the HTTP GET request:
    client.println("POST /test.xml HTTP/1.1");
    client.println("Host: tech-feast.000webhostapp.com");
    client.println("Connection: close");
    client.println();

 
  
  if (client.available()) 
  {
   
   for(;;) 
   {
    
    
    //char c = client.read();//
    
    //Serial.print(c);//
    


    xmlread();
    if (!client.connected())
   break;
    }
 

  }
  //*********************************************

  //**********************************************   
    // note the time that the connection was made:
    //lastConnectionTime = millis();

  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}


void xmlread() {
  
char inChar = client.read();
 
  if (inChar == '<') {
     addChar(inChar, tmpStr);
     tagFlag = true;
     dataFlag = false;
   } 
  
  
  else if (inChar == '>') {
     addChar(inChar, tmpStr);
     if (tagFlag) {      
        strncpy(tagStr, tmpStr, strlen(tmpStr)+1);
     }
     clearStr(tmpStr);
     tagFlag = false;
     dataFlag = true;         
   } 
  

  else if (inChar != 10)
  {
    if (tagFlag) 
     {
       addChar(inChar, tmpStr);
        if ( tagFlag && strcmp(tmpStr, endTag) == 0 )
         {
           clearStr(tmpStr);
           tagFlag = false;
           dataFlag = false;
         }
      }
      if (dataFlag) {
        addChar(inChar, dataStr);
     }
   }
   
   
   if (inChar == 10 ) {
    if (matchTag("<state>")) {
        
  Serial.print("state: ");
        Serial.println(dataStr);
        Serial.print("length--");
        Serial.println(strlen(dataStr));
        count=count+1;
        Serial.println(count);
       devicescontrol(count,dataStr);
       if(count==10)
       {
         count=0;
         
         clearStr(tmpStr);
         clearStr(tagStr);
         clearStr(dataStr);
         client.stop();
         client.flush();
         Serial.println("disconnecting.");
       }
        
     }
     clearStr(tmpStr);
     clearStr(tagStr);
     clearStr(dataStr);
     tagFlag = false;
     dataFlag = false;
  }
    


}


void clearStr (char* str) {
  int len = strlen(str);
  for (int c = 0; c < len; c++) {
     str[c] = 0;
  }
}


void addChar (char ch, char* str) {
  char *tagMsg  = "<ERROR>";
  char *dataMsg = "-ERROR";

 
  if (strlen(str) > MAX_STRING_LEN - 2) {
     if (tagFlag) {
        clearStr(tagStr);
        strcpy(tagStr,tagMsg);
     }
     if (dataFlag) {
        clearStr(dataStr);
        strcpy(dataStr,dataMsg);
     }
     clearStr(tmpStr);
     tagFlag = false;
     dataFlag = false;

  } 
  else {
     str[strlen(str)] = ch;
  }
}

boolean matchTag (char* searchTag) {
  if ( strcmp(tagStr, searchTag) == 0 ) {
     return true;
  } else {
     return false;
  }
}


void devicescontrol(int devicescount, char *devicestate)
{
  if(!strncmp("ON",devicestate,2))
  {
    Serial.print("on..........on......");
    Serial.println(devicescount);
    digitalWrite(devices[devicescount-1],HIGH);
  }
  else if(!strncmp("OFF",devicestate,3))
  {
    Serial.print("off......off.......");
    Serial.println(devicescount);
    digitalWrite(devices[devicescount-1],LOW);
  }
  
  
}

Anxiously waiting for your help…

that is how it is. the AT firmware sends the data over serial as soon as it receives it. the library can do nothing to stop it. the serial buffer overflows.

if you want to use AT firmware for this, you can use my new WiFiEspAT library, but it requires AT firmware 1.7.x (SDK 3) and doesn't support SSL for now.

This library uses the new passive receive mode implemented in AT firmware 1.7.0. It can communicate with AT firmware at high baud rates without flow control.

1 Like

Thank You for your reply I tried Your Library WiFiEspAT but there is no ssid and password and it is not connecting to the ESP8266 ESP-01 when i use WiFiEsp Library it is connecting and also working...
Please help me resolving this issue or suggest another library if necessary.... >:( @Juraj

SaadMustafa:
Thank You for your reply I tried Your Library WiFiEspAT but there is no ssid and password and it is not connecting to the ESP8266 ESP-01 when i use WiFiEsp Library it is connecting and also working...
Please help me resolving this issue or suggest another library if necessary.... >:( @Juraj

do you have AT firmware 1.7.x (SDK 3)?

read the README please GitHub - jandrassy/WiFiEspAT: Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.