Skip to content

Commit 29e7754

Browse files
author
Jeroen88
committed
Allocate BearSSL::WiFiClientSecure dynamically in StreamHttpsClient.ino
1 parent dc20696 commit 29e7754

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ void loop() {
4040

4141
HTTPClient http;
4242

43-
BearSSL::WiFiClientSecure client;
43+
BearSSL::WiFiClientSecure *client = new BearSSL::WiFiClientSecure ;
4444

45-
bool mfln = client.probeMaxFragmentLength("tls.mbed.org", 443, 1024);
45+
bool mfln = client->probeMaxFragmentLength("tls.mbed.org", 443, 1024);
4646
Serial.printf("\nConnecting to https://tls.mbed.org\n");
4747
Serial.printf("Maximum fragment Length negotiation supported: %s\n", mfln ? "yes" : "no");
4848
if (mfln) {
49-
client.setBufferSizes(1024, 1024);
49+
client->setBufferSizes(1024, 1024);
5050
}
5151

5252
Serial.print("[HTTPS] begin...\n");
5353

5454
// configure server and url
5555
const uint8_t fingerprint[20] = {0xEB, 0xD9, 0xDF, 0x37, 0xC2, 0xCC, 0x84, 0x89, 0x00, 0xA0, 0x58, 0x52, 0x24, 0x04, 0xE4, 0x37, 0x3E, 0x2B, 0xF1, 0x41};
56-
client.setFingerprint(fingerprint);
56+
client->setFingerprint(fingerprint);
5757

58-
if (http.begin(client, "https://tls.mbed.org/")) {
58+
if (http.begin(*client, "https://tls.mbed.org/")) {
5959

6060
Serial.print("[HTTPS] GET...\n");
6161
// start connection and send HTTP header
@@ -74,7 +74,7 @@ void loop() {
7474
static uint8_t buff[128] = { 0 };
7575

7676
// get tcp stream
77-
WiFiClient * stream = &client;
77+
WiFiClient * stream = client;
7878

7979
// read all data from server
8080
while (http.connected() && (len > 0 || len == -1)) {
@@ -107,6 +107,8 @@ void loop() {
107107
} else {
108108
Serial.printf("Unable to connect\n");
109109
}
110+
111+
delete client;
110112
}
111113

112114
delay(10000);

0 commit comments

Comments
 (0)