#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* host = "bibliotopia.cloudcart.net"; // Server from which data is to be fetched
const int httpsPort = 443; // Default port for HTTPS
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "20:3A:45:3C:1A:5D:10:D1:C6:BB:D4:92:FD:BC:DD:FF:27:5E:53:53"; // Fingerprint/Thumbprint for website bibliotopia.cloudcart.net
const int API_TIMEOUT = 40000; //keep it long if you want to receive headers from client
void setup() {
Serial.begin(115200);
Serial.println();
// Initialize Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
WiFiClientSecure client; // Use WiFiClientSecure class to create client instance
client.setInsecure();
client.setTimeout(API_TIMEOUT);
Serial.print("connecting to ");
Serial.println(host);
// delay(1000);
if (!client.connect(host, httpsPort)) { // establishing connection with the server(api.github.com) at port 443
Serial.println("connection failed");
return; // this line will return the function to the starting of void setup()
}
/*
if (client.verify(fingerprint, host)) { // verfying fingerprint with the server
Serial.println("certificate matches");
} else {
Serial.println("certificate doesn't match");
}
*/
String url = "/page/logotexnia?best-seller=nai-4"; //address from which we need to get the data inside the server.
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP32\r\n" +
"Connection: close\r\n\r\n");
/*
* GET /repos/esp8266/Arduino/commits/master/status HTTP/1.1
* Host : api.github.com
* User-Agent : BuildFailureDetectorESP8266
* Connection : close
*/
Serial.println("request sent");
while (client.connected()) { // until the client is connected, read out the response
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
while (client.available()) {
String line = client.readStringUntil('\n');
Serial.println(line);
}
/* if (line.startsWith("{\"state\":\"success\"")) {
Serial.println("esp32/Arduino CI successfull!");
} else {
Serial.println("esp32/Arduino CI has failed");
}*/
/* Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");*/
Serial.println("closing connection");
client.stop();
}
void loop() {
}