Component: Real Time Clock (ESP32) (Storage)
Author | Matrix TSL |
Version | 1.0 (Release) |
Category | Storage |
Contents
Real Time Clock (ESP32) component
Allows an ESP32 device to act as a RTC with NTP type server synchronisation. Requires a WIFI network connection with internet access to synchronise. Provides simulation using local PC system time.
Examples
A simple example that shows how to connect the ESP device to a network and synchronise the internal clock with an internet based NTP time server every hour.
The internal clock can drift over time and so it is important to sync regularily with the NTP time server.
For low power operations or when internet connectivity may be intermittent a 32.768KHz crystal can be used with the ESP32 device to improve the internal clock accuracy over time.
The crystal is fitted between pins IO32 and IO33 and must have 12pF capacitors to ground. The crystal must also be enabled by editing the sdkconfig file in the project compilation directory.
Downloadable macro reference
GetDateString
Collects the current date and returns it as a string.
e.g. "DD/MM/YY" or "MM/DD/YY"
Parameters
- BOOL USFormat
- Select date format: 0=DD/MM/YY, 1=MM/DD/YY
Return value
GetHours
No additional information
Parameters
- This macro has no parameters
Return value
GetSecs
No additional information
Parameters
- This macro has no parameters
Return value
GetYear
Gets the current month as a number 1 - 12
Parameters
- This macro has no parameters
Return value
QueryTimeServer
Attempt to collect the local time from the selected time server.
The ESP WIFI must be connected to a network with internet to allow this to work.
Returns true if the time server synchronised correctly with the ESP.
Parameters
- This macro has no parameters
Return value
- BOOL : Returns true if the operation is a success, else false
GetMins
No additional information
Parameters
- This macro has no parameters
Return value
GetTimeString
Collects the current time and returns it as a string.
e.g. "HH:MM" or "HH:MM:SS"
Parameters
- BOOL IncludeSeconds
- 0=Dont Include Seconds, 1=Include Seconds in the String
Return value
GetDate
No additional information
Parameters
- This macro has no parameters
Return value
SetTimeServer
Overwrites the default time server setting allowing for multiple time servers to be queried.
Parameters
- <- STRING TimeServer
- e.g. "pool.ntp.org"
- This parameter may be returned back to the caller
Return value
- This call does not return a value
GetMonth
Gets the current month as a number 1 - 12
Parameters
- This macro has no parameters
Return value
Initialise
Configures the timeserver variable as well as sets the timezone offset in seconds.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
SetUTCOffset
Allows the UTC Offset to be defined in seconds.
e.g. for BST use 3600 or for UTC+2 use 7200 or for UTC-2 use -7200
Parameters
- LONG UTCOffset
- Time offset in seconds
Return value
- This call does not return a value
Simulation macro reference
This component does not contain any simulation macros
Property reference
Time Server
This property is of type Line of text and can be referenced with the variable name TimeServer.
Default time server URL.
Set as part of the initialise macro.
Can be overridden using the SetTimeServer macro.
UTC Offset
This property is of type Unsigned integer and can be referenced with the variable name GMTOff.
Offset in seconds from UTC.
Set as part of the initialise macro.
Can be overridden using the SetUTCOffset macro.
Number of Retries
This property is of type Unsigned integer and can be referenced with the variable name NumRetries.
Sets the number of retries to connect to the SNTP server before giving up