I'm using the following libraries with the following two objects:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
WiFiClientSecure client;
HTTPClient sender;
Establishing a connection using the following code (works fine):
// connect to wifi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
uint8_t i = 0; // temp variable for while loop
while (WiFi.status() != WL_CONNECTED)
{
delay(200);
i++;
#ifdef DEBUG
Serial.print(".");
#endif
if (i == numOfWIFIConRetries)
{
#ifdef DEBUG
Serial.print(" Failed to connect to WIFI!");
while(1); // stuck here
#endif
}
}
The function I'm interesting in running several times, gets a char array (as pointer) and send it as a query displays the returned value. This works fine for the first time only. Why is that?
float queryWhatIsTheRate(char* coin)
{
String payload;
if (sender.begin(client, strcat(coin, "USDT"))))
{
if (sender.GET() == HTTP_CODE_OK)
{
payload = sender.getString();
#ifdef DEBUG
Serial.println(payload);
#endif
}
else
{
#ifdef DEBUG
//Serial.printf("HTTP-Error: ", sender.errorToString(httpCode).c_str());
Serial.printf("HTTP-error");
#endif
}
}
// temp return val
return 0;
}
So the first time would be a response from the website's API and the rest of the following calls would result in 'HTTP-Error' being printed.