     Serial.print(".");
   }
 
-  // With setInsecure() ou can tell BearSSL not to check the
-  // certificate of the server.  In this mode it will accept ANY certificate,
-  // which is subject to man-in-the-middle (MITM) attacks.
-  // check the following example for methods to verify the server:
-  // https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino
-  wifiClient.setInsecure();
+  // Validating  the SSL for for a secure connection you must
+  // set trust anchor, as well as set the time.
+  BearSSL::X509List cert(digicert);
+  wifiClient.setTrustAnchors(&cert);
+  setClock();
+  
 
   Serial.println("");
   Serial.println("WiFi connected");


bool ledState = false;

WiFiClientSecure wifiClient;

// For an unsecure connection to Losant.
// WiFiClient wifiClient;

LosantDevice device(LOSANT_DEVICE_ID);

void toggle() {
  Serial.println("Toggling LED.");

  Serial.print("Connecting to Losant...");

  device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

  while(!device.connected()) {
    delay(500);
