Difference between revisions of "Component: Real Time Clock (ESP32) (Storage)"
Line 1: | Line 1: | ||
− | + | {| style="width:50%" | |
− | |||
− | {| | ||
|- | |- | ||
− | | width="20%" style="color: gray;" | Author | + | | width="20%" style="color:gray;" | Author |
| Matrix TSL | | Matrix TSL | ||
|- | |- | ||
− | | width="20%" style="color: gray;" | Version | + | | width="20%" style="color:gray;" | Version |
− | | 1.0 | + | | 1.0 |
|- | |- | ||
− | | width="20%" style="color: gray;" | Category | + | | width="20%" style="color:gray;" | Category |
| Storage | | Storage | ||
|} | |} | ||
+ | ==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. | ||
+ | |||
+ | ==Detailed description== | ||
− | + | ''No detailed description exists yet for this component'' | |
− | |||
− | |||
− | |||
==Examples== | ==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. | 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. | ||
Line 36: | Line 37: | ||
==Downloadable macro reference== | ==Downloadable macro reference== | ||
− | === | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
− | Collects the current date and returns it as a string. | + | |- |
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetDateString''' | ||
+ | |- | ||
+ | | colspan="2" | Collects the current date and returns it as a string. e.g. "DD/MM/YY" or "MM/DD/YY" | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:]] - | ||
+ | | width="90%" | USFormat | ||
+ | |- | ||
+ | | colspan="2" | Select date format: 0=DD/MM/YY, 1=MM/DD/YY | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
− | ''' | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetHours''' | ||
+ | |- | ||
+ | | colspan="2" | Collects the current hour as a numeric value in the range of 0 - 23. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
− | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetSecs''' | ||
+ | |- | ||
+ | | colspan="2" | Collects the current second as a numeric value in the range of 0 - 59. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
− | :[[ | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetYear''' | ||
+ | |- | ||
+ | | colspan="2" | Collects the year as a numeric value in the range of 0 - 99. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | === | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
− | '' | + | |- |
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''QueryTimeServer''' | ||
+ | |- | ||
+ | | colspan="2" | 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. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:]] - | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadTime''' | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Unit | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
− | :'' | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetTime''' | ||
+ | |- | ||
+ | | colspan="2" | Manually sets the current time. Useful for when WIFI / NTP commnication is not available. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Hour | ||
+ | |- | ||
+ | | colspan="2" | Hour ranging from 0 to 23 | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Min | ||
+ | |- | ||
+ | | colspan="2" | Minute ranging from 0 to 59 | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Sec | ||
+ | |- | ||
+ | | colspan="2" | Second ranging from 0 to 59 | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | ''' | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetMins''' | ||
+ | |- | ||
+ | | colspan="2" | Collects the current minute as a numeric value in the range of 0 - 59. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetTimeString''' | ||
+ | |- | ||
+ | | colspan="2" | Collects the current time and returns it as a string. e.g. "HH:MM" or "HH:MM:SS" | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:]] - | ||
+ | | width="90%" | IncludeSeconds | ||
+ | |- | ||
+ | | colspan="2" | 0=Dont Include Seconds, 1=Include Seconds in the String | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
− | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadDate''' | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Unit | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | ''' | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetDate''' | ||
+ | |- | ||
+ | | colspan="2" | Manually sets the current date. Useful for when WIFI / NTP commnication is not available. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Date | ||
+ | |- | ||
+ | | colspan="2" | Day of the month ranging from 1 to 31 | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Month | ||
+ | |- | ||
+ | | colspan="2" | Month ranging from 1 to 12 | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Year | ||
+ | |- | ||
+ | | colspan="2" | Year ranging from 0 to 99 | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetDate''' | ||
+ | |- | ||
+ | | colspan="2" | Collects the day of the month as a numeric value in the range of 1 - 31. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
− | :[[ | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetTimeServer''' | ||
+ | |- | ||
+ | | colspan="2" | Overwrites the default time server setting allowing for multiple time servers to be queried. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING | ||
+ | | width="90%" | TimeServer | ||
+ | |- | ||
+ | | colspan="2" | e.g. "pool.ntp.org" | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | === | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
− | + | |- | |
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetMonth''' | ||
+ | |- | ||
+ | | colspan="2" | Collects the month as a numeric value in the range of 1 - 12. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
− | :'' | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' | ||
+ | |- | ||
+ | | colspan="2" | Configures the timeserver variable as well as sets the timezone offset in seconds. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | '''Return | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetUTCOffset''' | ||
+ | |- | ||
+ | | colspan="2" | 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 | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:]] - | ||
+ | | width="90%" | UTCOffset | ||
+ | |- | ||
+ | | colspan="2" | Time offset in seconds | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' | ||
+ | |- | ||
+ | | colspan="2" | Configures each matching sensor on the bus with the specified conversion bits. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Property reference== | ==Property reference== | ||
− | |||
− | + | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | |
− | + | |- | |
− | Default time server URL. | + | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]] |
− | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | |
− | Set as part of the initialise macro. | + | |- |
− | + | |- | |
− | Can be overridden using the SetTimeServer macro. | + | | width="10%" align="center" | [[File:Fc9-type-10-icon.png]] |
− | + | | width="90%" | Time Server | |
− | + | |- | |
− | + | | colspan="2" | Default time server URL. Set as part of the initialise macro. Can be overridden using the SetTimeServer macro. | |
− | + | |- | |
− | + | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | |
− | Offset in seconds from UTC. | + | | width="90%" | UTC Offset |
− | + | |- | |
− | Set as part of the initialise macro. | + | | colspan="2" | Offset in seconds from UTC. Set as part of the initialise macro. Can be overridden using the SetUTCOffset macro. |
− | + | |- | |
− | Can be overridden using the SetUTCOffset macro. | + | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] |
− | + | | width="90%" | Number of Retries | |
− | + | |- | |
− | + | | colspan="2" | Sets the number of retries to connect to the SNTP server before giving up | |
− | + | |- | |
− | + | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]] | |
− | Sets the number of retries to connect to the SNTP server before giving up | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Connections''' |
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Simulations''' | ||
+ | |- | ||
+ | |} |
Revision as of 20:58, 16 November 2021
Author | Matrix TSL |
Version | 1.0 |
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.
Detailed description
No detailed description exists yet for this component
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" | |
[[File:]] - | USFormat |
Select date format: 0=DD/MM/YY, 1=MM/DD/YY | |
![]() |
Return |
![]() |
GetHours |
Collects the current hour as a numeric value in the range of 0 - 23. | |
![]() |
Return |
![]() |
GetSecs |
Collects the current second as a numeric value in the range of 0 - 59. | |
![]() |
Return |
![]() |
GetYear |
Collects the year as a numeric value in the range of 0 - 99. | |
![]() |
Return |
![]() |
ReadTime |
![]() |
Unit |
![]() |
Return |
![]() |
GetMins |
Collects the current minute as a numeric value in the range of 0 - 59. | |
![]() |
Return |
![]() |
GetTimeString |
Collects the current time and returns it as a string. e.g. "HH:MM" or "HH:MM:SS" | |
[[File:]] - | IncludeSeconds |
0=Dont Include Seconds, 1=Include Seconds in the String | |
![]() |
Return |
![]() |
ReadDate |
![]() |
Unit |
![]() |
Return |
![]() |
GetDate |
Collects the day of the month as a numeric value in the range of 1 - 31. | |
![]() |
Return |
![]() |
SetTimeServer |
Overwrites the default time server setting allowing for multiple time servers to be queried. | |
![]() |
TimeServer |
e.g. "pool.ntp.org" | |
![]() |
Return |
![]() |
GetMonth |
Collects the month as a numeric value in the range of 1 - 12. | |
![]() |
Return |
![]() |
Initialise |
Configures the timeserver variable as well as sets the timezone offset in seconds. | |
![]() |
Return |
![]() |
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 | |
[[File:]] - | UTCOffset |
Time offset in seconds | |
![]() |
Return |
![]() |
Initialise |
Configures each matching sensor on the bus with the specified conversion bits. | |
![]() |
Return |