{"id":77,"date":"2026-02-25T22:36:03","date_gmt":"2026-02-25T21:36:03","guid":{"rendered":"https:\/\/elrebo.de\/?p=77"},"modified":"2026-02-25T22:36:06","modified_gmt":"2026-02-25T21:36:06","slug":"time_sync","status":"publish","type":"post","link":"https:\/\/www.elrebo.de\/index.php\/2026\/02\/25\/time_sync\/","title":{"rendered":"time_sync"},"content":{"rendered":"\n<p id=\"block-0cfb8a78-7f9c-4098-b4fe-b30608000cbc\">An ESP-IDF component for <a href=\"https:\/\/elrebo.de\/index.php\/2026\/02\/20\/physical-computing\/\">Physical Computing<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-4b033aba-2a31-4956-b5d1-36a5f063d6a0\">Purpose<\/h2>\n\n\n\n<p id=\"block-d1d08013-14c7-41d6-bc31-31fd7f00b092\">Time synchronization for ESP32 systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-c0ec4b6c-cd95-4697-b800-d5a8e2dcf602\">How it is done<\/h2>\n\n\n\n<p id=\"block-f813434c-ae67-4bed-8e0b-5e80c7f0b3e2\">You need to include&nbsp;<code>time_sync.hpp<\/code>&nbsp;and<\/p>\n\n\n\n<p>provide a function&nbsp;<code>timeTask<\/code>&nbsp;for the task which synchronizes the time periodically.<\/p>\n\n\n\n<p>After establishing a Wifi connection the&nbsp;<code>TimeSync<\/code>&nbsp;class must be initialized and<\/p>\n\n\n\n<p>the timeTask must be started.<\/p>\n\n\n\n<p>From then on the time will be synchronized.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-c316dbcb-c3c9-4a23-a3c7-d4fd1e0eb867\">Where to find it<\/h2>\n\n\n\n<p id=\"block-cc2afcf8-a2c3-4f6c-842a-a2443cfb1062\"><code>time_sync<\/code> is published on the ESP Registry at <a href=\"https:\/\/components.espressif.com\/components\/elrebo-de\/time_sync\">https:\/\/components.espressif.com\/components\/elrebo-de\/time_sync<\/a>.<\/p>\n\n\n\n<p id=\"block-2ecaabd6-5bb7-4287-bcc4-985ff1c232d5\">The source code can be found at <a href=\"https:\/\/github.com\/elrebo-de\/time_sync\">https:\/\/github.com\/elrebo-de\/time_sync<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-cf4dee0e-a35e-4163-9fb2-e2fc7ece1f67\">How to use it<\/h2>\n\n\n\n<p id=\"block-931617c6-8adf-4eb4-85d7-1ac4f0d6a9ed\">As an ESP-IDF component <code>time_sync<\/code> must be included into idf_component.yml as a dependency. As usual this can be done by executing this command:<\/p>\n\n\n\n<p id=\"block-37ac3466-38c9-435c-9301-59bc3384f2e1\"><code>idf.py add-dependency \"elrebo-de\/time_sync^1.2.0\"<\/code><\/p>\n\n\n\n<p id=\"block-c35797fb-de02-421b-aecd-512cb88904a4\">In CMakeLists.txt <code>\"elrebo-de__time_sync\"<\/code> has to be added as a requirement.<\/p>\n\n\n\n<p id=\"block-e64a7152-e2b3-46ce-bc41-7ca22badb118\">Now you can include <code>time_sync.hpp<\/code> and use the TimeSync class in your program.<\/p>\n\n\n\n<p id=\"block-e64a7152-e2b3-46ce-bc41-7ca22badb118\">The TimeSync class is implemented as a Singleton. With this code it is initialized:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"164\" src=\"https:\/\/elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.24.28-1024x164.png\" alt=\"\" class=\"wp-image-111\" srcset=\"https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.24.28-1024x164.png 1024w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.24.28-300x48.png 300w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.24.28-768x123.png 768w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.24.28-1536x246.png 1536w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.24.28.png 1712w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p id=\"block-e64a7152-e2b3-46ce-bc41-7ca22badb118\">Now the timeTask has to be started, which will then synchronize time every SyncIntervalMs milliseconds.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"182\" src=\"https:\/\/elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.29.06-1024x182.png\" alt=\"\" class=\"wp-image-113\" srcset=\"https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.29.06-1024x182.png 1024w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.29.06-300x53.png 300w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.29.06-768x136.png 768w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.29.06-1536x272.png 1536w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.29.06.png 1714w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p id=\"block-e64a7152-e2b3-46ce-bc41-7ca22badb118\">After this code snippet time is synchronized!<\/p>\n\n\n\n<p>The timeTask is implemented like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"346\" src=\"https:\/\/elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.30.56-1024x346.png\" alt=\"\" class=\"wp-image-114\" srcset=\"https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.30.56-1024x346.png 1024w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.30.56-300x101.png 300w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.30.56-768x260.png 768w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.30.56-1536x519.png 1536w, https:\/\/www.elrebo.de\/wp-content\/uploads\/2026\/02\/Bildschirmfoto-2026-02-25-um-22.30.56.png 1656w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>First it gets the pointer to the <code>TimeSync<\/code> Singleton. Then it uses the methods <code>obtainTime<\/code>, <code>printCalendar<\/code> and <code>getSyncIntervalMs<\/code> to synchronize time every <code>SyncIntervalMs<\/code> milliseconds.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An ESP-IDF component for Physical Computing Purpose Time synchronization for ESP32 systems. How it is done You need to include&nbsp;time_sync.hpp&nbsp;and provide a function&nbsp;timeTask&nbsp;for the task which synchronizes the time periodically. After establishing a Wifi connection the&nbsp;TimeSync&nbsp;class must be initialized and the timeTask must be started. From then on the time will be synchronized. Where to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":115,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-77","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oss"],"_links":{"self":[{"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":4,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":152,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/posts\/77\/revisions\/152"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/media\/115"}],"wp:attachment":[{"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}