Anniversary Sale · up to 80% off all librariesEnds Nov 9Shop now
SOFTTDocs
Cards
You are reading the documentation for ESP-DASH v4.x.x, which is no longer the latest release. View the v5.x.x documentation.

Time Sync Card

Synchronize the device clock with the browser time from the ESP-DASH Pro v4 dashboard.

ESP-DASH Pro feature. This functionality is available only in the commercial edition of ESP-DASH.

The time sync card sends the current time from the browser to the device. Use it to set the device clock from the dashboard.

Time sync card

The time is taken from the browser. Use this card only when the browser and the device are in the same timezone.

Constructor

Card timeSync(&dashboard, TIME_SYNC_CARD, "Time Sync");

Prop

Type

Callback

The callback fires when the user triggers a sync on the dashboard. value contains the time reported by the browser.

timeSync.attachCallback([&](const char* value) {
  Serial.println("Time sync: " + String(value));
});

Example

main.cpp
#include <Arduino.h>
#if defined(ESP8266)
  #include <ESP8266WiFi.h>
  #include <ESPAsyncTCP.h>
#elif defined(ESP32)
  #include <WiFi.h>
  #include <AsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include <ESPDash.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

AsyncWebServer server(80);
ESPDash dashboard(&server);

Card timeSync(&dashboard, TIME_SYNC_CARD, "Time Sync");

void setup() {
  Serial.begin(115200);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("WiFi connection failed");
    return;
  }
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  timeSync.attachCallback([&](const char* value) {
    Serial.println("Time sync: " + String(value));
  });

  server.begin();
}

void loop() {
  // ...
}

Notes

  • The time sync card does not need update().

On this page