🛠 Serveur web sur le port Ethernet 10/100 embarqué

Arduino Portenta H7 · intermediaire · Schéma : IMG-portenta-h7-intermediaire-3-portenta-h7-serveur-web-ethernet.svg — Portenta H7 reliée par un câble RJ45 (via porteuse ou connecteurs 80 broches) à un switch, un navigateur laptop affichant la page servie par l'IP de la carte, étiquettes PHY 10/100 et connecteurs 80 broches

Objectives

The Portenta H7 offers more than just Wi-Fi: an Ethernet 10/100 PHY is soldered onto the board, exposed via the 80-pin connector pair (the Max/Mid Carrier boards provide the RJ45 connector). In an industrial workshop, wired connections beat wireless: stable latency, no association management required. You will build a wired mini HTTP server, in the spirit of the official "Ethernet with the IDE" tutorial for the Portenta range.

Hardware

Complete Code

// serveur_web_eth.ino — mini serveur HTTP sur Ethernet filaire
// > 
// inits pins) pour le core Mbed — la base documentaire ne donne pas le
// code exact ; suis le tuto officiel ethernet-with-ide de docs.arduino.cc
// pour la config materielle de ta porteuse.
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EthernetServer serveur(80);

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

  if (Ethernet.begin(mac) == 0) {
    Serial.println("DHCP Ethernet echoue");
    while (true) {}
  }
  Serial.print("Serveur sur http://");
  Serial.println(Ethernet.localIP);
}

void loop {
  EthernetClient client = serveur.available;
  if (client) {
    String requete = client.readStringUntil('\r');
    client.flush;
    String page = "<h1>Bonjour depuis ma Portenta H7</h1>"
                  "<p>Ethernet 10/100 embarque</p>";
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.print("Content-Length: ");
    client.println(page.length);
    client.println("Connection: close");
    client.println;
    client.print(page);
    client.stop;
    Serial.println("requete servie : " + requete);
  }
}

Expected Verification

The serial monitor displays the IP address assigned by DHCP; point your browser to it to see the page. Each reload logs the GET request on the console. The official combo "Vision Shield camera + Ethernet" (tutorial ethernet-with-ide) takes it further: streaming images over the wired LAN.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials