mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Make HTTPClient take a WiFiClient parameter, allowing you to pass in a simple HTTP WiFiClient or a BearSSL or axTLS WiFiClientSecure with any desired verification options. Deprecate the older, TLSTraits methods. Add basic HttpsClient example. Add optional LED feedback to the Update class
79 lines
1.9 KiB
C++
79 lines
1.9 KiB
C++
/**
|
|
BasicHTTPSClient.ino
|
|
|
|
Created on: 20.08.2018
|
|
|
|
*/
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <ESP8266WiFi.h>
|
|
#include <ESP8266WiFiMulti.h>
|
|
|
|
#include <ESP8266HTTPClient.h>
|
|
|
|
#include <WiFiClientSecureBearSSL.h>
|
|
// Fingerprint for demo URL, expires on June 2, 2019, needs to be updated well before this date
|
|
const uint8_t fingerprint[20] = {0x5A, 0xCF, 0xFE, 0xF0, 0xF1, 0xA6, 0xF4, 0x5F, 0xD2, 0x11, 0x11, 0xC6, 0x1D, 0x2F, 0x0E, 0xBC, 0x39, 0x8D, 0x50, 0xE0};
|
|
|
|
ESP8266WiFiMulti WiFiMulti;
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
// Serial.setDebugOutput(true);
|
|
|
|
Serial.println();
|
|
Serial.println();
|
|
Serial.println();
|
|
|
|
for (uint8_t t = 4; t > 0; t--) {
|
|
Serial.printf("[SETUP] WAIT %d...\n", t);
|
|
Serial.flush();
|
|
delay(1000);
|
|
}
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
WiFiMulti.addAP("SSID", "PASSWORD");
|
|
}
|
|
|
|
void loop() {
|
|
// wait for WiFi connection
|
|
if ((WiFiMulti.run() == WL_CONNECTED)) {
|
|
|
|
BearSSL::WiFiClientSecure client;
|
|
client.setFingerprint(fingerprint);
|
|
|
|
HTTPClient https;
|
|
|
|
Serial.print("[HTTPS] begin...\n");
|
|
if (https.begin(client, "https://jigsaw.w3.org/HTTP/connection.html")) { // HTTPS
|
|
|
|
|
|
Serial.print("[HTTPS] GET...\n");
|
|
// start connection and send HTTP header
|
|
int httpCode = https.GET();
|
|
|
|
// httpCode will be negative on error
|
|
if (httpCode > 0) {
|
|
// HTTP header has been send and Server response header has been handled
|
|
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
|
|
|
|
// file found at server
|
|
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
|
|
String payload = https.getString();
|
|
Serial.println(payload);
|
|
}
|
|
} else {
|
|
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
|
|
}
|
|
|
|
https.end();
|
|
} else {
|
|
Serial.printf("[HTTPS] Unable to connect\n");
|
|
}
|
|
}
|
|
|
|
delay(10000);
|
|
}
|