// Read data from the web server
bool read_web_data()
{
HTTPClient HTTP;
// currency_names: {"Bitcoin", "Ethereum", "Litecoin", "Monero"};
String cur = currency_names[currency_index];
cur.toLowerCase(); // Force to lowercase
String uri = "/public/v1/coins/" + cur + "?currency=EUR";
// Get a quote (in euros) for the specified cryptocurrency
// "https://api.coinstats.app/public/v1/coins/bitcoin?currency=EUR"
// Pass a list of root certificates so the identity of the server
// can be validated.
http.begin("https://api.coinstats.app" + uri, root_ca);
int httpCode = http.GET();
bool success = false;
if (httpCode == HTTP_CODE_OK)
{
if (decode_web_data(http.getStream()))
success = true;
else
Serial.println("Web data decoding failed");
}
else
{
Serial.printf("Connection to API failed, error: %s\r\n", http.errorToString(httpCode).c_str());
}
http.end();
return success;
}