🛠 Client HTTPS/TLS : interroger une API sécurisée via le Murata 1DX
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
- 1 × Arduino Portenta H7 + USB-C data cable
- Wi-Fi access point with Internet access
- "Arduino Mbed OS Portenta Boards" core; Secrets tab filled (
SECRET_SSID,SECRET_PASS) - Serial console at 115200 baud
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
- Server with a self-signed certificate or incomplete chain: validation fails and
connectreturns false with little detail — test first with a public site with a valid certificate. - >
- Chunked/gzip response: this example reads raw bytes; some APIs compress — add
Accept-Encoding: identityto stay in plain text. - Forgetting the
Hostheader in HTTP/1.1: virtual hosts return a 400 error or the wrong site. - Never calling
client.stop: the remote server keeps the connection open and may refuse subsequent ones. - Confusing with BLE: the Murata 1DX also supports Bluetooth 5.1 (Classic + LE, official tutorial
ble-connectivity) — but for web APIs, it is indeed Wi-Fi +WiFiSSLClient. - Captive networks (hotels, corporate Wi-Fi):
WiFi.begin"connects" but TLS fails until the browser has validated the portal.
Other tutorials for this board
- Premier programme : installer le core et faire clignoter la LED (M7 à 480 MHz !)
- Se connecter au Wi-Fi avec le module Murata 1DX (station WPA2)
- Apprivoiser les connecteurs 80 broches : bouton, LED et entrée analogique
- Dual-core M7 ↔ M4 : appels de fonctions distants avec la bibliothèque RPC
- Serveur web sur le port Ethernet 10/100 embarqué
- MicroPython + machine vision : le firmware OpenMV sur un cœur, C++ sur l'autre
Code examples for this board
clignotante.inoArduinobouton-poussoir.inoArduinopwm-respiration.inoArduinoentree-analogique.inoArduinomulti-uart.inoArduinocapteur-i2c-bmp280.inoArduino