Docs
RTC
The RTC widget gives your board the current time. The server sends it, so a board with no clock chip still knows what time it is.
Use it when the sketch itself needs the time: a log with timestamps, a display showing the clock, logic that behaves differently at night.
| Setting | What it does |
|---|---|
| Time zone | the zone the time arrives in |
Open these from the canvas: tap Edit, then long press the widget and choose Configure.
The widget needs no pin. Add it to the project and the time reaches any board in it.
Example
Print the time to a Value widget every minute.
#include <TimeLib.h>
#include <PlynxSimpleEsp32.h>
#include <WidgetRTC.h>
WidgetRTC rtc;
PlynxTimer timer;
void sendTime()
{
char buf[16];
snprintf(buf, sizeof(buf), "%02d:%02d", hour(), minute());
Plynx.virtualWrite(V27, buf);
}
PLYNX_CONNECTED()
{
rtc.begin(); // ask the server for the time
}
void setup()
{
Serial.begin(115200);
// Auto setup: WiFi and the Plynx token are configured from the app.
//
// To provide them directly in the sketch instead, use:
// Plynx.begin(auth, ssid, pass);
Plynx.begin();
timer.setInterval(60000L, sendTime);
}
void loop()
{
Plynx.run();
timer.run();
} rtc.begin() belongs in PLYNX_CONNECTED(). Calling it in setup() asks
before there is a connection to answer.
The RTC needs the Time library by Paul Stoffregen, which provides hour(),
minute(), day() and the rest.
Accuracy is a few seconds. It suits logs and schedules, not anything that counts milliseconds.
Troubleshooting
| Problem | Check |
|---|---|
| Time stays at 1970 | rtc.begin() never ran, or ran before the connection |
| Time is off by hours | the time zone in the widget settings |
Compile error on hour() | the Time library is not installed |
| Time drifts after days offline | the board only syncs when it reconnects |