horloge-wifi.ino

Arduino GIGA R1 WiFi · File : horloge-wifi.ino · Language : Arduino · Use case : Donner l'heure exacte grâce au Wi-Fi

The GIGA WiFi's 1DX module joins an access point like a classic shield: SNTP gives true time that the CAN bus or PLC won't have on its own. The u.FL antenna is mandatory.

Hardware required

An Arduino GIGA R1 WiFi (STM32H747, 1DX radio module: Wi-Fi b/g/n + BLE, u.FL antenna included), powered over USB-C. A 2.4 GHz Wi-Fi box; the supplied u.FL antenna, screwed on without fail.

Wiring

No wiring. Fit the antenna before powering up; keep it away from metal enclosure walls.

How it works

WiFi.begin drives the radio co-processor; configTime arms the kernel SNTP. RSSI and IP on the monitor serve as range diagnostics. In the Arduino IDE, « Arduino Zephyr-based Boards » platform, « Arduino Giga R1 » board; fit the u.FL antenna before using the radio, then Upload.

Going further

Timestamp CAN frames with this time, or show it on the dedicated sketch's OLED.

horloge-wifi.ino

// GIGA R1 WiFi : heure NTP via le module 1DX, affichee sur le port serie.
#include <WiFi.h>

const char *SSID = "votre-wifi";
const char *CLE = "votre-cle";

void setup() {
  Serial.begin(115200);
  WiFi.begin(SSID, CLE);
  while (WiFi.status() != WL_CONNECTED) { delay(300); Serial.print("."); }
  Serial.printf("\nIP %s — RSSI %d dBm\n",
                WiFi.localIP().toString().c_str(), WiFi.RSSI());
  configTime(3600 * 2, 0, "pool.ntp.org");   // UTC+2, sans DST
}

void loop() {
  struct tm t;
  time_t maintenant = time(nullptr);
  localtime_r(&maintenant, &t);
  Serial.printf("%04d-%02d-%02d %02d:%02d:%02d  rssi %d\n",
                t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
                t.tm_hour, t.tm_min, t.tm_sec, WiFi.RSSI());
  delay(1000);
}

← Back to the board