Also, once I get this working, I have a few more questions please:
1. It looks like HTTPClient.GET() stores the whole page into RAM. This will be a problem for me. Is there any way to read the page char-by-char? As you can see in my sample sketch, I've tried using HTTPClient.getStream() but based on the heap sizes it seems it still stores the whole page on the heap under the hood.
2. If I"m willing to accept the chance of being spoofed, is there any way to connect to an https site without needing to deal with the fingerprint stuff?
Many thanks for any help.
Elwood Downey
Tuscon Arizona
#include <Arduino.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
static char ssid[] = "clearskyinstitute"; // your network SSID (name)
static char pass[] = "from651plan"; // your network password
void setup() {
Serial.begin (115200);
Serial.print ("heap 1: "); Serial.println (ESP.getFreeHeap());
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("no shield");
while (1)
ESP.wdtFeed();
}
// we only want station mode, not access too
WiFi.mode(WIFI_STA);
Serial.println ("connecting to WiFi");
WiFi.begin (ssid, pass); // non-blocking, poll with status()
uint32_t t0 = millis();
uint32_t timeout = 15000UL;
while (WiFi.status() != WL_CONNECTED) {
ESP.wdtFeed();
if (millis() > t0 + timeout) {
Serial.println ("no wifi");
while(1);
ESP.wdtFeed();
}
delay(1000);
}
Serial.print ("heap 2: "); Serial.println (ESP.getFreeHeap());
Serial.println ("trying connection");
HTTPClient sdo_http;
ESP.wdtFeed();
if (!sdo_http.begin ("https://sdo.gsfc.nasa.gov/assets/img/latest/f_211_193_171_170.jpg",
"8D 6B 9B BD AC E4 55 A8 D1 CA 54 67 6F 22 FE 9D 1A F1 2E 70")) {
// if (!sdo_http.begin ("https://www.wired.com/index.html",
// "E8 BC F9 5F 59 AB 96 13 00 3D 0E 59 46 6C 6B 5E 7A AA 12 82")) {
Serial.println ("begin fails");
while (1)
ESP.wdtFeed();
}
Serial.print ("heap 3: "); Serial.println (ESP.getFreeHeap());
int get_status = sdo_http.GET();
ESP.wdtFeed();
if (get_status < 0) {
Serial.print ("GET: "); Serial.println (sdo_http.errorToString(get_status));
while (1)
ESP.wdtFeed();
}
Serial.print ("heap 4: "); Serial.println (ESP.getFreeHeap());
WiFiClient sdo_client = sdo_http.getStream();
while (sdo_client.connected()) {
while (!sdo_client.available())
ESP.wdtFeed();
(void) sdo_client.read();
// Serial.print(sdo_client.read());
}
Serial.print ("heap 5: "); Serial.println (ESP.getFreeHeap());
sdo_client.stop();
Serial.print ("heap 6: "); Serial.println (ESP.getFreeHeap());
sdo_http.end();
yield();
Serial.print ("heap 7: "); Serial.println (ESP.getFreeHeap());
}
void loop() {
Serial.print ("heap: "); Serial.println (ESP.getFreeHeap());
for (uint8_t i = 0; i < 10; i++) {
delay(1000);
ESP.wdtFeed();
}
}
Output:
heap 1: 41216
connecting to WiFi
heap 2: 40984
trying connection
heap 3: 40680
GET: connection refused