I'm trying to access the following website (public API for Binance): https://api.binance.com/api/v3/ticker/price
On any browser, without a specific query, it will display a list of crypto coins and their USD exchange rates. This is the list I would like to save for further processing and parsing.
Since this is an HTTPS, I'm setting the wificlient to insecure so won't authenticate against the website. I'm also assuming port 443 - which might be a source for error.
Obviously ssid + password are updated to my home wifi. The ESP8266 connects and does not write there is an HTTP error so I guess it does manage to log on but does not get the page I see on my browser but rather a blank page?
Here is my current code:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
const char* ssid = "ssid";
const char* password = "password";
WiFiClientSecure client;
HTTPClient sender;
void setup()
{
Serial.begin(115200); // serial monitoring
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(200);
Serial.print(".");
}
Serial.print("Connected to WIFI!");
client.setInsecure();
client.connect("https://api.binance.com/api/v3/ticker/price", 443);
if (sender.begin(client, "https://api.binance.com/api/v3/ticker/price"))
{
int httpCode = sender.GET();
if (httpCode > 0)
{
if (httpCode == HTTP_CODE_OK)
{
String payload = sender.getString();
Serial.println("\nHTTP_CODE_OK");
Serial.println(payload);
}
else
{
Serial.printf("HTTP-Error: ", sender.errorToString(httpCode).c_str());
}
}
}
else
{
Serial.printf("Other HTTP error");
sender.end();
}
}
void loop()
{
}