User avatar
By Rish
#73997 hi everyone
i am getting a connection refused error and otherwise nothing is getting printed on the serial monitor.

Code: Select all

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#define USE_SERIAL Serial
int id,temp_id=0,i=0;
ESP8266WiFiMulti wifiMulti;
void setup() {
     
    USE_SERIAL.begin(115200);
    delay(100);
    WiFi.mode(WIFI_STA);
    wifiMulti.addAP("DIGISOL", "edot2018");

    while (wifiMulti.run() != WL_CONNECTED) { // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above
    delay(250);
    Serial.print(".");
  }

}

void loop() {
       
        HTTPClient http,http2;
        http.begin("http://192.168.1.12/FlightStats/api/Flight/GetArrivingFlightsStatus/"); //HTTP
        delay(250);
        http2.begin("http://192.168.1.12/FlightStats/api/Flight/GetDepartingFlightsStatus/");
        delay(250);
        if(http.begin("http://192.168.1.12/FlightStats/api/Flight/GetArrivingFlightsStatus/") == false) {
           USE_SERIAL.println("http.begin() failed");
          exit(0);
        }   
        //start connection and send HTTP header
        int httpCode = http.GET();
        int httpCode2 = http2.GET();
        // [HTTP] GET... failed, error: connection refused
       if(httpCode > 0 && httpCode2 > 0) {
            // HTTP header has been send and Server response header has been handled
            // file found at server
            if(httpCode == HTTP_CODE_OK && httpCode2 == HTTP_CODE_OK) {
                String myString = http.getString();
                String myString2 = http2.getString();

                const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + 370;
                 DynamicJsonBuffer jsonBuffer(bufferSize);
                 JsonObject& root = jsonBuffer.parseObject(myString);
                 const char* descpription = root["Description"];
                 JsonObject& root1 = jsonBuffer.parseObject(myString2);
                 const char* descpription2 = root1["Description"];
                  if(i=0){
                 USE_SERIAL.println(descpription);
                 USE_SERIAL.println(descpription2);
                 i=1;
                  }
            }
        }
        else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }
        http.end();
}




help plz