Setting time and date
The first step to be able to use the RTC is setting time and date. Some functions have been created for managing these operations.
Setting time and date
It sets time and date on the RTC.
Time and date are specified by inputs which correspond to the different variables: year, month, date, day, hour, minute and second.
day
is the day of the week and the range for this value is 1 to 7. By default, Sunday is equal to 1 and Saturday is equal to 7.
The setTime()
function extracts each part of date and time, storing each part in the corresponding variable. After this, the registersRTC
array is loaded with these variables and data is sent to the RTC.
This function returns '0' if was successfully executed. In the case of any error '1' is returned.
Example of use:
Related variables:
year
, month
, hour
, minute
, second
→ stores the time and date set
day
→ stores the day of the week
date
→ stores the day of the month
An example of the functions: https://development.libelium.com/rtc-01-setting-and-reading-time/
An example of how to set RTC via USB port: https://development.libelium.com/rtc-07-set-waspmote-date/
Getting time and date
The getTime()
function gets time and date, storing them in the registersRTC
array and the corresponding variables. This function updates all API variables related to time and date:
RTC.year
RTC.month
RTC.date
RTC.day
RTC.hour
RTC.minute
RTC.second
It returns a string containing time and date in the following format: "Day of week, yy/mm/dd, hh:mm:ss". In the case an error happened, the"error" message is returned.
Example of use:
Related variables:
year
, month
, hour
, minute
, second
→ stores the time and date set
day
→ stores the day of the week
date
→ stores the day of the month
An example of the functions: https://development.libelium.com/rtc-01-setting-and-reading-time/
Getting day of week
This function calculates the day of the week based on the year, month and day. Sakamoto's algorithm is used in this function. Valid for any date in the range [September 14, 1.752] - [December 31, 9.999].
The inputs for dow()
function are: year, month and day of month.
Example of use:
The function returns:
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Last updated