Getting Time Zone and Daylight Savings info out of CTS

I'm currently getting the CTS info out of my iPhone and storing it in my RTC, that talks with my nRF52832 via I2C.  All seems to work.

But my Dev Team are now wanting the time in UTC, which means I also need Time Zone and Daylight Savings Time info.  The standard API's that Nordic provide only seems to extract the Current Time:

/**@brief "Exact Time 256" field of the Current Time characteristic. */
struct bt_cts_exact_time_256 {
	uint16_t year;
	uint8_t month;
	uint8_t day;
	uint8_t hours;
	uint8_t minutes;
	uint8_t seconds;
	uint8_t day_of_week;
	uint8_t fractions256;
};

/**@brief "Adjust Reason" field of the Current Time characteristic. */
struct bt_cts_adjust_reason {
	uint8_t manual_time_update : 1;
	uint8_t external_reference_time_update : 1;
	uint8_t change_of_time_zone : 1;
	uint8_t change_of_daylight_savings_time : 1;
};

/**@brief Data structure for the Current Time characteristic. */
struct bt_cts_current_time {
	struct bt_cts_exact_time_256 exact_time_256;
	struct bt_cts_adjust_reason adjust_reason;
};

What I also need is the Local Time info.

Has anyone done this before, and if so, can you give me a bit of guidance on how to go about this?

I assume I need to create a new struct, a-la:

/** Local Time Information Characteristic structure */
struct bt_cts_local_time
{
    int8_t timeZone;           /**< Current Time Zone */
    uint8_t dst;               /**< Daylight Saving Time value */
};

And then when I read the CTS from my phone, I need to index the Local Time characteristic from the CTS and copy it into an instance of the above struct.  Does that sound correct?

Its this last step I'm not 100% sure of, nor how to go about implementing it, so any guidance will be warmly received :-)

Cheers,

Mike

Parents
  • I looked into this.

    Looking at this document: Current Time Service.

    I see that the CTS Service can contain both a Current Time characterstic and a Local Time information characterstic.

    The Current Time characteristic contains the time local time, adjusted for DST and time zone. See 3.1.1 in the attached document:

    "The date and time values returned shall be the local date and time of the server device (the time the server device would display to the user, which is normally the correct time for the location adjusted for time zone and DST)."

    Next, you would then need to include the Local Time Information characterstic, and use that to get the Time zone field and the DST offset field

    Then you can get the UTC time by subtracting the DST offset field and Time zone field from the current local time you got from the Current Time characteristic.

    I've not gone into the speficics of how to do this, but try to check out the Peripheral CTS client sample, it demonstrates how to get all these fields: Peripheral CTS Client

    Best regards,

    Simon

  • Next, you would then need to include the Local Time Information characterstic, and use that to get the Time zone field and the DST offset field

    That's the issue.  The Nordic API's only extract the Current Time characteristic, and don't include the Local Time characteristic.  And I can't work out how I can get that info myself.

    My code that extracts the Current Time characteristic is based on that Peripheral CTS Client example.

    I "think" all I need to do is read a Gatt characteristic, and use the Local Time characteristic handle to reference that, but I'm floundering around trying to work out how to do that.

    BTW - think I've nailed the Local->UTC conversion thing myself.

    Cheers,

    Mike

Reply
  • Next, you would then need to include the Local Time Information characterstic, and use that to get the Time zone field and the DST offset field

    That's the issue.  The Nordic API's only extract the Current Time characteristic, and don't include the Local Time characteristic.  And I can't work out how I can get that info myself.

    My code that extracts the Current Time characteristic is based on that Peripheral CTS Client example.

    I "think" all I need to do is read a Gatt characteristic, and use the Local Time characteristic handle to reference that, but I'm floundering around trying to work out how to do that.

    BTW - think I've nailed the Local->UTC conversion thing myself.

    Cheers,

    Mike

Children
Related