🛠 Se connecter au WiFi et lire l'heure NTP (WiFiS3)

Arduino UNO R4 WiFi · intermediaire · Schéma : IMG-uno-r4-wifi-intermediaire-1-ur4wifi-wifi-station-ntp.svg — UNO R4 WiFi avec antention WiFi en en-tête, puce ESP32-S3 annotée « modem WiFi 2,4 GHz + BLE », routeur à gauche, serveur NTP à droite, moniteur série affichant un horodatage.

Objectives

Leverage the board's second chip: the embedded ESP32-S3 acts as a WiFi (2.4 GHz only) and Bluetooth Low Energy modem, controlled from the RA4M1 via the official WiFiS3 library. You will connect to a WPA2 network, retrieve the time from an NTP server, and understand the "two brains" model: the RA4M1 runs your sketch, while the ESP32-S3 runs its own WiFi stack and communicates with the RA4M1 over UART.

Hardware

Full Code

#include <WiFiS3.h>

const char* SSID = "votre-reseau";
const char* PASS = "votre-cle";

void setup {
  Serial.begin(115200);
  while (!Serial && millis < 5000) { }  // laisse le temps d'ouvrir le Moniteur

  Serial.print(F("Connexion a ")); Serial.println(SSID);
  WiFi.setTimeout(20000);          // patience : 20 s max
  int status = WiFi.begin(SSID, PASS);
  if (status != WL_CONNECTED) {
    Serial.print(F("Echec, code ")); Serial.println(status);
    while (true) { }               // en prod : réessayer, pas boucler
  }
  Serial.print(F("IP = ")); Serial.println(WiFi.localIP);

  unsigned long epoch = WiFi.getTime;   // requête NTP via l'ESP32-S3
  Serial.print(F("Epoch NTP = ")); Serial.println(epoch);
}

void loop {
  if (WiFi.status != WL_CONNECTED) {
    Serial.println(F("WiFi perdu, reconnexion..."));
    WiFi.disconnect;
    WiFi.begin(SSID, PASS);
  }
  delay(1000);
}

Expected Verification

The Monitor displays a local IP address (192.168.x.x) followed by a consistent Unix timestamp (≈ 1.7–1.8 billion seconds). Unplug the WiFi router: WiFi.status goes offline and the reconnection loop takes over.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials