Reads the time from a BLE device that offers the Current Time Service (a phone, a watch, a TinyCTSServer, ...). It is also a TinyCTSTimeSource.
More...
|
| | TinyCTSClient (const char *device=nullptr, uint32_t scanMs=5000) |
| | TinyCTSClient (const char *device=nullptr, uint32_t scanMs=5000) |
| | TinyCTSClient (const char *device=nullptr, uint32_t scanMs=5000) |
| | TinyCTSClient (const char *device=nullptr, uint32_t scanMs=5000) |
| bool | begin () |
| | Find the device and read the time.
|
| bool | begin () |
| | Start the BLE hardware, find the device and read the time.
|
| bool | begin () |
| | Find the device and read the time. NimBLEDevice::init() is called, if the NimBLE stack is not initialized yet.
|
| bool | begin () |
| | Start the BLE hardware, find the device and read the time.
|
|
const std::string & | getLastError () const |
| | The reason why the last call failed.
|
|
uint32_t | getRoundTripMs () const |
| | The round trip time of the last read or write in ms (the connection interval).
|
| std::vector< TinyCTSScanEntry > | scan (uint32_t timeoutMs) |
| | List the devices that are in range.
|
|
void | setAdapter (const char *name) |
| | The Bluetooth adapter to use (Linux only, default: hci0).
|
| bool | setTimeMs (uint64_t unixMs) override |
| | Set the time of the device by writing the Current Time. It works if the device allows it; if it requires an encrypted connection, pair it first.
|
| bool | setTimeMs (uint64_t unixMs) override |
| | Set the time of the device by writing the Current Time. It works if the device allows it (and the connection is paired, if it requires it).
|
| bool | setTimeMs (uint64_t unixMs) override |
| | Set the time of the device by writing the Current Time. It works if the device allows it (and the connection is paired, if it requires it).
|
| bool | setTimeMs (uint64_t unixMs) override |
| | Set the time of the device by writing the Current Time. It works if the device allows it (and the connection is paired, if it requires it).
|
|
bool | setTimeZone (const TinyCTSLocalTimeInfo &info) |
| | Set the time zone of the device by writing its Local Time Information (if the device allows it).
|
| bool | update () |
| | Read the time (and the other characteristics) again: the device is connected, read and disconnected.
|
| bool | update () |
| | Read the time (and the other characteristics) again: the device is connected, read and disconnected.
|
| bool | update () |
| | Read the time (and the other characteristics) again: the device is connected, read and disconnected.
|
| bool | update () |
| | Read the time (and the other characteristics) again: the device is connected, read and disconnected.
|
|
const TinyCTSCurrentTime & | getCurrentTime () const |
| | The Current Time as it was sent by the device.
|
|
const std::string & | getDeviceAddress () const |
| | The address of the device that was used.
|
|
const std::string & | getDeviceName () const |
| | The name of the device that was used (empty before begin()).
|
|
const TinyCTSLocalTimeInfo & | getLocalTimeInfo () const |
| | The time zone of the device (valid after update() if it has it).
|
|
std::tm | getLocalTm () |
| | The local time as std::tm, with the offsets of the device.
|
|
const TinyCTSReferenceTimeInfo & | getReferenceTimeInfo () const |
| | Where the time of the device comes from.
|
|
uint32_t | getTime () |
| | The UTC time in seconds since 1970-01-01 (0 if not known).
|
| uint64_t | getTimeMs () override |
| | The UTC time in ms since 1970-01-01, extrapolated since the last update.
|
|
std::tm | getTm () |
| | The UTC time as std::tm.
|
|
void | setLocalTimeInfo (const TinyCTSLocalTimeInfo &info) |
| | Tell the client the time zone of the device, if it does not have the Local Time Information. Used for the local time and, with setTimeIsLocal(), when the time is set.
|
|
void | setTimeIsLocal (bool local) |
| | The Current Time of the device is the local time, not UTC.
|
Reads the time from a BLE device that offers the Current Time Service (a phone, a watch, a TinyCTSServer, ...). It is also a TinyCTSTimeSource.
Reads the time from a BLE device that offers the Current Time Service (a phone, a watch, a TinyCTSServer, ...). It is also a TinyCTSTimeSource, so the time can be served by a TinyCTSServer.
This is the version for the desktop. The functions block until they are done. begin() scans for the device, connects, reads the characteristics and disconnects: the time is then extrapolated with the clock of the computer. The getters are in TinyCTSClientBase.
if (cts.
begin()) printf(
"%llu\n", (
unsigned long long)cts.
getTimeMs());
uint64_t getTimeMs() override
The UTC time in ms since 1970-01-01, extrapolated since the last update.
Definition TinyCTSClientBase.h:32
bool begin()
Find the device and read the time.
Definition TinyCTSClientDesktop.h:51
TinyCTSClient(const char *device=nullptr, uint32_t scanMs=5000)
Definition TinyCTSClientDesktop.h:39
const std::string & getLastError() const
The reason why the last call failed.
Definition TinyCTSClientDesktop.h:134
begin() starts the BLE hardware (BLE.begin()), scans for the device, connects, reads the characteristics and disconnects: the time is then extrapolated with millis(). Call update() from time to time (e.g. once per hour) to stay in sync. The functions block until they are done. The getters are in TinyCTSClientBase.
void setup() {
}
uint32_t getTime()
The UTC time in seconds since 1970-01-01 (0 if not known).
Definition TinyCTSClientBase.h:41
begin() scans for the device, connects, reads the characteristics and disconnects: the time is then extrapolated with millis(). Call update() from time to time (e.g. once per hour) to stay in sync. The getters are in TinyCTSClientBase.
Select "Tools -> IP/Bluetooth Stack -> IPv4 + Bluetooth". begin() starts the BLE hardware (do not call BLE.begin() yourself), scans for the device, connects, reads the characteristics and disconnects: the time is then extrapolated with millis(). Call update() from time to time (e.g. once per hour) to stay in sync. The functions block until they are done. The getters are in TinyCTSClientBase.