🛠 HTTPS avec validation de certificat racine

Arduino MKR WiFi 1010 · avance · Schéma : IMG-mkr-wifi-1010-avance-1-mkrwifi-https-certificats.svg — Poignée de main TLS entre le WiFiSSLClient de la MKR WiFi 1010 et un serveur HTTPS, le certificat du serveur étant vérifié contre le magasin de CA racines stocké dans le module NINA.

Objectives

Move from plain HTTP to HTTPS using WiFiSSLClient: the TLS handshake is handled by the NINA module, which verifies the server certificate against its internal store of root CAs (bundle rebuilt from the Android list, embedded by the nina-fw firmware). You will learn how to diagnose validation failures and cope with known TLS bugs in the firmware.

Hardware

Complete code

#include <WiFiNINA.h>

const char* SSID = "votre-ssid";
const char* PASS = "votre-mot-de-passe";
WiFiSSLClient secure;   // TLS + validation CA embarquee dans le NINA

void setup {
  Serial.begin(115200);
  WiFi.begin(SSID, PASS);
  while (WiFi.status != WL_CONNECTED) { delay(500); Serial.print("."); }

  if (secure.connect("www.howsmyssl.com", 443)) {
    secure.println("GET /a/check HTTP/1.1");
    secure.println("Host: www.howsmyssl.com");
    secure.println("Connection: close");
    secure.println;
    while (secure.available) Serial.write(secure.read);
    secure.stop;                       // libere la session TLS
  } else {
    Serial.println("Handshake TLS KO - firmware/CA a verifier");
  }
}

void loop {}

Expected verification

The JSON response from howsmyssl is displayed, proving that the channel is encrypted and the certificate is validated. secure.connect returns 0 as long as the issuing CA is not in the module's bundle: update the firmware first before suspecting your code. Always call stop: each TLS session consumes the NINA's precious RAM.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials