Consumo de api retorna -1 no ESP8266

Olá, pessoal!

Estou tentando consumir uma API, porém não funciona, ele se conecta a internet, más retorna -1 no HTTPCODE

Não coloquei a URL da API por questoes de segurança.

codigo:

#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

char* SSID = "iPhone";
char* SENHA = "gabi1234";

char* BASE_URL = "URLDAAPI";

void initSerial();
void initWiFi();

WiFiClient client;
HTTPClient http;

void setup() {
initSerial();
initWiFi();
}

void loop() {
makeRequest();
delay(2000);
}

void initSerial() {
Serial.begin(115200);
}

void initWiFi() {
delay(10);
Serial.println("Conectando-se em: " + String(SSID));

WiFi.begin(SSID, SENHA);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println();
Serial.print("Conectado na Rede " + String(SSID) + " | IP => ");
Serial.println(WiFi.localIP());
}

String makeRequest()
{
http.begin(client,BASE_URL);
int httpCode = http.GET();
Serial.println(httpCode);

if (httpCode < 0) {
return "request error - " + httpCode;

}

if (httpCode != HTTP_CODE_OK) {
return "Diferente " + httpCode;
}

String response = http.getString();
http.end();

return response;
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.