#include #include //#include #include #include HTTPClient client; BearSSL::WifiClientSecure *transport; BearSSL::X509List cert_list; void init_wifi() { transport = new WifiClientSecure(); Serial.println("Attempting to (re)connect to wifi"); WiFi.disconnect(); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); int elapsed = 0; while (WiFi.status() != WL_CONNECTED) { Serial.print("Wifi connecting for "); Serial.print(elapsed); Serial.println(" seconds"); elapsed++; delay(1000); } Serial.println("Wifi connected"); sync_time(); load_ca_cert(); } void load_ca_cert() { // read cert from file if (!SPIFFS.begin()) { Serial.println("Failed to mount file system."); return } File cert = SPIFFS.open("/ca_cert.pem", "r"); if (!cert) { Serial.println("Couldn't open cert file."); return; } cert_list.append(strdup(cert.readString().c_str())); netClient->setTrustAnchors(&certList); } void sync_time() { // sync time Serial.print("Syncing time"); configTime(8 * 3600, 0, "pool.ntp.org", "time.nist.gov"); time_t now = time(nullptr); while (now < 8 * 3600 * 2) { delay(500); Serial.print("."); now = time(nullptr); } Serial.println(""); }