Skip to content

Instantly share code, notes, and snippets.

@igrr
Created November 26, 2015 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrr/816523b463bd7d045b77 to your computer and use it in GitHub Desktop.
Save igrr/816523b463bd7d045b77 to your computer and use it in GitHub Desktop.
/*
* HTTP over TLS (HTTPS) example sketch
*
* This example demonstrates how to use
* WiFiClientSecure class to access HTTPS API.
* We fetch and display the status of
* esp8266/Arduino project continous integration
* build.
*
* Created by Ivan Grokhotkov, 2015.
* This example is in public domain.
*/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <time.h>
const char* ssid = " ";
const char* password = " ";
const char* host = "api.github.com";
const int httpsPort = 443;
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
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());
configTime(3600, 0, "pool.ntp.org");
}
void loop() {
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
String url = "/repos/esp8266/Arduino/commits/esp8266/status";
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
// Serial.println("waiting for connection to close");
while (client.connected() || client.available()) {
client.read();
}
time_t t = time(nullptr);
Serial.printf("time: %s\tHeap: %d\n", ctime(&t), ESP.getFreeHeap());
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment