A BLE peripheral that offers the Current Time Service (0x1805) and serves the time of a time source to the BLE clients (phones, watches, boards with a TinyCTSClient).
More...
|
| bool | begin (TinyCTSTimeSource &source, const char *deviceName="TinyCTS") |
| | Register the service and start the advertising.
|
| bool | begin (TinyCTSTimeSource &source, const char *deviceName="TinyCTS") |
| | Start the BLE hardware, the service and the advertising.
|
| bool | begin (TinyCTSTimeSource &source, const char *deviceName="TinyCTS") |
| | Start the service and the advertising. NimBLEDevice::init() is called with the name, if the NimBLE stack is not initialized yet.
|
| bool | begin (TinyCTSTimeSource &source, const char *deviceName="TinyCTS") |
| | Start the BLE hardware, the service and the advertising.
|
|
void | end () |
| | Unregister the service and stop the advertising.
|
|
void | end () |
| | Stop advertising.
|
|
void | end () |
| | Stop advertising.
|
|
void | end () |
| | Stop advertising.
|
|
const std::string & | getLastError () const |
| | The reason why begin() failed.
|
|
uint32_t | getRequestCount () const |
| | The number of values that the clients have read.
|
|
bool | notifyTime (uint8_t adjustReason=0) |
| | Notify the subscribed clients now.
|
|
bool | notifyTime (uint8_t adjustReason=0) |
| | Notify the subscribed clients now.
|
|
bool | notifyTime (uint8_t adjustReason=0) |
| | Notify the subscribed clients now.
|
|
bool | notifyTime (uint8_t adjustReason=0) |
| | Notify the subscribed clients now.
|
| bool | process () |
| | Handle the requests of the clients and send the notifications. Call this regularly in loop().
|
| bool | process () |
| | Call this regularly in loop(): it handles the requests of the clients and sends the notifications.
|
| bool | process () |
| | Call this regularly in loop(): it sends the notifications.
|
| bool | process () |
| | Call this regularly in loop(): it sends the notifications.
|
|
void | setAdapter (const char *name) |
| | The Bluetooth adapter to use (Linux only, default: hci0). Call it before begin().
|
| void | enableTimeSetting (bool requireEncryption=true) |
| | Allow the clients to set the time of the time source by writing the Current Time (and the time zone by writing the Local Time Information). Needs a time source that implements setTimeMs(). Call it before begin().
|
|
uint32_t | getTimeSetCount () const |
| | The number of times that a client has set the time.
|
|
void | setNotifyInterval (uint32_t ms) |
| | Notify the subscribed clients regularly in process(). 0 (default): only when the time was set or the time zone changed. The specification asks for a notification when the time changes by a larger step: use a long interval, e.g. 60000 ms.
|
|
void | setReferenceInfo (uint8_t source, uint8_t accuracy=255) |
| | Where the time comes from and how exact it is (125 ms steps).
|
|
void | setTimeIsLocal (bool local) |
| | The Current Time contains the local time (UTC + the offsets of the Local Time Information) instead of UTC (default). Some clients expect the local time. Call it before begin().
|
| void | setTimeZone (int utcOffsetMinutes, int dstMinutes=0) |
| | The time zone that is offered in the Local Time Information.
|
|
|
void | onRead (BLECharacteristic *chr) override |
|
void | onRead (NimBLECharacteristic *chr, NimBLEConnInfo &) override |
| bool | onRead (uint16_t uuid, std::vector< uint8_t > &value) override |
| void | onReferenceChanged () override |
| void | onReferenceChanged () override |
| void | onReferenceChanged () override |
| void | onTimeZoneChanged () override |
| void | onTimeZoneChanged () override |
| void | onTimeZoneChanged () override |
| void | onTimeZoneChanged () override |
|
void | onWrite (BLECharacteristic *chr) override |
|
void | onWrite (NimBLECharacteristic *chr, NimBLEConnInfo &) override |
| bool | onWrite (uint16_t uuid, const uint8_t *data, size_t len) override |
|
void | updateCurrent (uint8_t reason) |
|
void | updateCurrent (uint8_t reason) |
|
void | updateCurrent (uint8_t reason, bool notify) |
|
void | updateLocal () |
|
void | updateLocal () |
|
void | updateLocal () |
|
void | updateReference () |
|
void | updateReference () |
|
void | updateReference () |
| size_t | currentTimeValue (uint8_t reason, uint8_t *out) |
|
size_t | localTimeValue (uint8_t *out) const |
| bool | notifyDue () |
|
size_t | referenceTimeValue (uint8_t *out) const |
| bool | setTimeFromWrite (const uint8_t *data, size_t len) |
| bool | setTimeZoneFromWrite (const uint8_t *data, size_t len) |
A BLE peripheral that offers the Current Time Service (0x1805) and serves the time of a time source to the BLE clients (phones, watches, boards with a TinyCTSClient).
A BLE peripheral that offers the Current Time Service (0x1805) and serves the time of a time source to the BLE clients (phones, watches, other boards running a TinyCTSClient, tinycts on the desktop).
This is the version for the desktop. The computer must have a Bluetooth adapter that can be a peripheral. Call process() in your loop: on Linux it handles the requests of BlueZ, on the other systems they are answered by a thread of the system, which also calls the time source. The settings are in TinyCTSServerBase. Only one server per process is possible.
The name of the device is only used on Linux and macOS: Windows advertises the name of the computer.
TinyCTSServer server;
if (!server.
begin(source,
"my-computer")) fprintf(stderr,
"%s\n", server.
getLastError().c_str());
while (running) { server.
process(); sleep_ms(10); }
void setTimeZone(int utcOffsetMinutes, int dstMinutes=0)
The time zone that is offered in the Local Time Information.
Definition TinyCTSServerBase.h:39
void end()
Unregister the service and stop the advertising.
Definition TinyCTSServerDesktop.h:72
bool begin(TinyCTSTimeSource &source, const char *deviceName="TinyCTS")
Register the service and start the advertising.
Definition TinyCTSServerDesktop.h:55
const std::string & getLastError() const
The reason why begin() failed.
Definition TinyCTSServerDesktop.h:105
bool process()
Handle the requests of the clients and send the notifications. Call this regularly in loop().
Definition TinyCTSServerDesktop.h:84
The UTC time of the system clock (gettimeofday()). Not available on the boards without gettimeofday()...
Definition TinyCTSTimeSource.h:114
It provides the characteristics Current Time (read, notify), Local Time Information and Reference Time Information (read). While the time source returns 0 (time not known) the Current Time is reported with an unknown date.
begin() starts the BLE hardware (BLE.begin()). Call process() in loop(): it calls BLE.poll(), which handles the requests of the clients. Only one server per program is possible. The settings are in TinyCTSServerBase.
With enableTimeSetting() the writable characteristics need an encrypted connection: ArduinoBLE then asks for it also for reading them.
TinyCTSServer server;
void setup() {
clock.setTime(1767225600);
server.
begin(clock,
"my-clock");
}
A software clock: you set the UTC time (from an RTC, a GPS, ...) and it keeps counting with millis()....
Definition TinyCTSTimeSource.h:79
It provides the characteristics Current Time (read, notify), Local Time Information and Reference Time Information (read). While the time source returns 0 (time not known) the Current Time is reported with an unknown date.
Call begin() once and process() in loop() if you want periodic notifications (setNotifyInterval()). The settings are in TinyCTSServerBase.
TinyCTSServer server;
void setup() {
clock.setTime(rtc.now().unixtime());
server.
begin(clock,
"my-clock");
}
It provides the characteristics Current Time (read, notify), Local Time Information and Reference Time Information (read). While the time source returns 0 (time not known) the Current Time is reported with an unknown date.
Select "Tools -> IP/Bluetooth Stack -> IPv4 + Bluetooth". begin() starts the BLE hardware: do not call BLE.begin() yourself. The Bluetooth callbacks read the time source: it must be fast and not block. Call process() in loop() if you want periodic notifications (setNotifyInterval()). The settings are in TinyCTSServerBase.
TinyCTSServer server;
void setup() {
clock.setTime(1767225600);
server.
begin(clock,
"my-clock");
}