/*
* Simple HTTP get webclient test
*/
#include
const char* ssid = "ssid"; //change your wifi ssid
const char* password = "password"; //change to your wifi password
#define HOST "api.twitch.tv"
#define PATH "/helix/streams?user_id=125913611"
#define CLIENTID "YOURCLIENTID" //change to your client id.
#define REFRESH 20 // seconds between refresh
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char fingerprint[] PROGMEM = "F I N G E R P R I N T";
void setup() {
Serial.begin(115200);
delay(100);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(HOST);
// Use WiFiClient class to create TCP connections
WiFiClientSecure client;
client.setFingerprint(fingerprint);
if (!client.connect(HOST, 443)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
Serial.print("Requesting URL: ");
Serial.println(PATH);
// This will send the request to the server
client.print(String("GET ") + PATH + " HTTP/1.1\r\n" +
"Host: " + HOST + "\r\n" +
"Client-ID: " + CLIENTID + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
int32_t timeout = millis() + 1000;
while (client.available() == 0) {
if (timeout - millis() < 0) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
boolean isStreaming = false;
while (client.connected()) {
if (client.find("\"type\":{\"live\":")) {
isStreaming = true;
}
Serial.print(isStreaming);
}
delay(REFRESH*1000);
}
/*
For instance on Chrome press Ctrl+Shift+I and go to Security > View Certificate > Details > Thumbprint. This will show a window like below where you can copy the fingerprint and paste it into sketch.
*/