🛠 Client HTTPS/TLS : interroger une API sécurisée via le Murata 1DX

Arduino Portenta H7 · intermediaire · Schéma : IMG-portenta-h7-intermediaire-2-portenta-h7-client-tls.svg — Portenta H7 envoyant un tunnel TLS en pointillés verts vers un serveur web distant via la box Internet, cadenas sur le tunnel, terminal série affichant le début de la réponse HTTP, étiquette certificats en flash

Objectives

Move from "connected" Wi-Fi to "useful" Wi-Fi: talk to a server over TLS (HTTPS). The Mbed core provides WiFiSSLClient, a TCP socket that automatically negotiates TLS encryption — trusted certificates are stored in the board's flash, which eliminates the need for a real-time clock for the handshake. You will build an HTTP/1.1 request by hand on this client, the basic pattern for consuming any API.

Hardware

Full code

// client_tls.ino — modele l'exemple WiFiSSLClient du core
#include <WiFi.h>
#include "arduino_secrets.h"

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int status = WL_IDLE_STATUS;

WiFiSSLClient client;        // TLS : pas d'RTC necessaire,
                             // le certificat est en flash

void setup {
  Serial.begin(9600);
  while (!Serial) {}

  if (WiFi.status == WL_NO_MODULE) {
    Serial.println("Module Murata 1DX non detecte !");
    while (true) {}
  }
  while (status != WL_CONNECTED) {
    Serial.print("Connexion a "); Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(3000);
  }
  Serial.print("IP : "); Serial.println(WiFi.localIP);

  if (client.connect("www.google.com", 443)) {
    client.println("GET / HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println;
    while (client.available) Serial.write(client.read);
    client.stop;
  } else {
    Serial.println("Poignee de main TLS echouee");
  }
}

void loop {}

Expected verification

After the Wi-Fi connection, the TLS handshake runs (a few hundred ms — the 480 MHz machine performs the crypto calculations), then the page's HTML is displayed on the console. Replace the host with a JSON API for real-world usage: same lines, adapted Host header, then parse the response body.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials