connection refused error for multiple http request

hi

i am using esp8266 module with arduino uno board.

i am able to upload the sketch in the esp8266 and it works fine until i make another http GET request.

ERROR

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v4ceabea9
~ld

[HTTP] GET… code: 200
{“Description”:"SG 923 AMD 16:30 SCH "}

[HTTP] GET… code: 200
{“Description”:"SG 923 AMD 16:30 SCH "}

[HTTP] GET… failed, error: connection refused

[HTTP] GET… failed, error: connection refused

esp8266 code

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
void setup() {
    USE_SERIAL.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFiMulti.addAP("DIGISOL", "edot2018");

}

void loop() {
    
    if((WiFiMulti.run() == WL_CONNECTED)) {
        HTTPClient http;
        USE_SERIAL.print("[HTTP] begin...\n");
        http.begin("http://192.168.1.12/FlightStats/api/Flight/GetArrivingFlightsStatus/"); //HTTP
        USE_SERIAL.print("[HTTP] GET...\n");
        int httpCode = http.GET();
        if(httpCode > 0) {
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }
        http.end();
    }
    delay(5000);
}

help plz

esp8266 code

    delay(5000);
}

help plz

That last part won't even compile.

ESP8266WiFiMulti WiFiMulti;

Why do you need ESP8266WiFiMulti? Post a link to this library.

delay(5000);
}

help plz

That last part won't even compile.

Sorry this "help plz" was suppose to be outside the code tag ::slight_smile:

Why do you need ESP8266WiFiMulti? Post a link to this library.

if there are more then one wifi network then it selects best of those two.

but i think wifi should not affect the http get command, because i am connecting to wifi in the setup at once in the setup.

and i am able to get the http code 200 twice after that m getting connection refused error.

If you are sometimes able to connect, and sometimes not, I think you should be looking at the server to see why it is refusing some connections.

Sorry this "help plz" was suppose to be outside the code tag

We don't do text-speak here.

If you are sometimes able to connect, and sometimes not, I think you should be looking at the server to see why it is refusing some connections.

but this code works without any error with the robotDyn Uno wifi board.

Any news on this? I have the same problem. My first GET succeeds, but all subsequent GETs fail with ‘connection refused’. Here is my function which is called from a timer every 60 seconds. I have also tried calling the function from a button press instead of the timer. The WIFI status is always reported as ‘CONNECTED’. I also have a ‘ESP8266WebServer’ running which is accessible.

void updateDomoticz(){
  if(!connected){
    Serial.println("Not connected to WIFI");
  }else{
    String str;
    if(relayStatus==1)
      str = "/json.htm?type=command&param=udevice&idx="+String(data.idx)+"&nvalue=1&svalue=On";
    else
      str = "/json.htm?type=command&param=udevice&idx="+String(data.idx)+"&nvalue=0&svalue=Off";

    Serial.println("Sending:"+str);
    HTTPClient client;
    client.begin(String(data.IP),data.port,str);
    int resp = client.GET();
    if(resp<0){
      Serial.println("Domoticz failure:"+client.errorToString(resp));
    }else{
      Serial.println("Domoticz responded with "+String(resp));
    }
    client.end();
  }
}

kingrolo:
Any news on this? I have the same problem. My first GET succeeds, but all subsequent GETs fail with ‘connection refused’. Here is my function which is called from a timer every 60 seconds. I have also tried calling the function from a button press instead of the timer. The WIFI status is always reported as ‘CONNECTED’. I also have a ‘ESP8266WebServer’ running which is accessible.

Have you found a solution ?
I have the same problem.

I’m getting the same issue. I have 3 instances on the HTTPClient and they all work once only. I’m definitely calling end. https.GET() returns 0 or less and https.errorToString(httpCode).c_str() is connection refused. Everything was fine until I tried to use https and added client->setInsecure(). Snipit below.

if (WiFi.status() == WL_CONNECTED) {// Check WiFi connection status
std::unique_ptrBearSSL::WiFiClientSecureclient(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https; // Declare an object of class HTTPClient
https.begin(*client, url); // Specify request destination
int httpCode = https.GET(); //Send the request
if (httpCode > 0) { // Check the returning code
line = https.getString(); // Get the request response payload
} else {
quoteString=String(“HTTPS GET failed, error:”) + https.errorToString(httpCode).c_str();
Serial.println(quoteString);
https.end();
return false;
}
https.end(); //Close connection
// Serial.print(“Response :”); Serial.println(line); // debug info
} else {
quoteString=“Wifi connection failed”;
Serial.println(quoteString);
return false;
}