AD

이게 작동하면 좋겠네요.진짜 진짜 최종 수정본!!

용접기사
2019-04-22 23:59:22 492 1 2

/*
* 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.

ref. https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/client-secure-examples.html?highlight=Secure

*/

후원댓글 2
댓글 2개  
이전 댓글 더 보기
TWIP 잔액: 확인중
0
04-19
0
04-19
4
04-14
3
도트가성
미야모토루리
04-13
4
04-09
2
04-09
1
공수완료^^7 [1]
㈖연산
04-03
2
3성 가붕이 [1]
뱁닭
03-31
2
03-28
2
등장콘도 받아랏 [1]
흥미롭군요
03-28
3
사식콘입니다
흥미롭군요
03-28
1
03-28
1
03-27
2
03-26
1
03-25
1
03-24
인기글 글 쓰기