BLEClientCts is a helper class that implements adopted Current Time Service , which enables you to receive time from devices such as an iPhone or iPad.
// Callback Signatures typedef void (*adjust_callback_t) (uint8_t reason); BLEClientCts(void); virtual bool begin(void); virtual bool discover(uint16_t conn_handle); bool getCurrentTime(void); bool getLocalTimeInfo(void); bool enableAdjust(void); void setAdjustCallback(adjust_callback_t fp); // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.current_time.xml struct ATTR_PACKED { uint16_t year; uint8_t month; uint8_t day; uint8_t hour; uint8_t minute; uint8_t second; uint8_t weekday; uint8_t subsecond; uint8_t adjust_reason; } Time; // https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.local_time_information.xml struct ATTR_PACKED { int8_t timezone; uint8_t dst_offset; }LocalInfo;
Client CTS OLED Example
The client_cts_oled example uses the Adafruit FeatherWing OLED to display received time.
Sketch Requirements
In order to use this example sketch the following libraries must be installed on your system:
Loading the Sketch
The client_cts_oled sketch can be loaded via the examples menu under Peripheral > client_cts_oled:
With the sketch loaded, you can build the firmware and then flash it to your device via the Upload button or menu option. Once the sketch is running on the nRF52 Feather you can proceed with the one-time pairing process, described below.
Pairing to your Mobile Device
Before you can start receiving notifications, you will need to 'pair' the nRF52 Feather and the mobile device.
The pairing process causes a set of keys to be exchanged and stored on the two devices so that each side knows it is talking to the same device it originally bonded with, and preventing any devices in the middle from eavesdropping on potentially sensitive data.
The one-time pairing process is described below, and assumes you are already running the ancs_oled sketch on your nRF52 device.
1. In the Settings app go to Bluetooth:
2. Scroll to the bottom of the list of 'My Devices' and click on Bluefruit52 under Other Devices:
3. When the pairing dialog box comes up, click the Pair button:
4. Wait for the pairing process to complete, at which point Bluefruit52 should appear in the My Devices list with the Connected status:
Wait for Time Data
At this point, time data from the mobile device will be read and display on the the OLED. For demo purpose the sketch will read time data from mobile once every second. However, in reality, nRF52 should have an internal timer that keep track of second, and only read/sync with mobile after several hours or days, similar to how IP device got time from NTP server.
Text editor powered by tinymce.