Repository navigation
Server Time Sources
pschatzmann edited this page Nov 1, 2026
·
2 revisions
TinyCTSServer::begin() takes a TinyCTSTimeSource: an object that knows the current UTC time in milliseconds since 1970-01-01. While getTimeMs() returns 0 (time not known), the server reports a Current Time with an unknown date.
| Class | Time from |
|---|---|
TinyCTSClockSource |
A software clock that you set (RTC, GPS, ...) and that counts with millis()
|
TinyCTSSystemSource |
The system clock (gettimeofday(), std::chrono on the desktop). Not on AVR and Uno R4 |
TinyCTSClient |
Another BLE device: a BLE time repeater |
TinyCTSSourceAdapter<T> |
Any object with a getTimeMs(), e.g. the TinyNTPClient of TinyNTP |
| your class | Derive from TinyCTSTimeSource
|
TinyCTSClockSource clock_;
clock_.setTime(rtc.now().unixtime()); // seconds since 1970 (and optionally ms)
server.begin(clock_);Set it regularly (e.g. every few minutes); it must be read or set at least once every 49 days because of the overflow of millis().
configTime(0, 0, "pool.ntp.org"); // ESP32: set the clock with SNTP (UTC)
TinyCTSSystemSource source;
server.begin(source);Times before 2023-11-14 are treated as "clock not set".
class MySource : public TinyCTSTimeSource {
public:
uint64_t getTimeMs() override { return myClock.unixMs(); }
bool setTimeMs(uint64_t ms) override { return myClock.set(ms); } // optional
};getTimeMs() is called for each request, so it must be fast and must not block. setTimeMs() is only called if you allowed the clients to set the time (see Security); the default refuses.