{"id":764,"date":"2018-02-06T23:27:07","date_gmt":"2018-02-06T14:27:07","guid":{"rendered":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/?post_type=jetpack-portfolio&#038;p=764"},"modified":"2018-02-25T14:20:49","modified_gmt":"2018-02-25T05:20:49","slug":"year-2038-countdown-clock","status":"publish","type":"jetpack-portfolio","link":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/portfolio\/year-2038-countdown-clock\/","title":{"rendered":"Year 2038 countdown clock"},"content":{"rendered":"<div class=\"entry-content\" itemprop=\"text\">\nhttps:\/\/youtu.be\/E-os8XCysBw?cc_load_policy=1&amp;rel=0&amp;autoplay=1<\/p>\n<div class=\"carousel slide\" id=\"custom-carousel-0\" data-ride=\"carousel\"><ol class=\"carousel-indicators\"><li class=\"active\" data-target=\"#custom-carousel-0\" data-slide-to=\"0\"><\/li><li class=\"\" data-target=\"#custom-carousel-0\" data-slide-to=\"1\"><\/li><li class=\"\" data-target=\"#custom-carousel-0\" data-slide-to=\"2\"><\/li><li class=\"\" data-target=\"#custom-carousel-0\" data-slide-to=\"3\"><\/li><\/ol><div class=\"carousel-inner\">\n<div class=\"item active\">\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1406-1024x768.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\" size-large wp-image-770\" srcset=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1406-1024x768.jpg 1024w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1406-300x225.jpg 300w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1406-768x576.jpg 768w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1406-640x480.jpg 640w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1406-48x36.jpg 48w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><br \/>\n<\/div>\n<div class=\"item\">\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1506-3-1024x768.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\" size-large wp-image-771\" srcset=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1506-3-1024x768.jpg 1024w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1506-3-300x225.jpg 300w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1506-3-768x576.jpg 768w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1506-3-640x480.jpg 640w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1506-3-48x36.jpg 48w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><br \/>\n<\/div>\n<div class=\"item\">\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1505-1024x768.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\" size-large wp-image-772\" srcset=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1505-1024x768.jpg 1024w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1505-300x225.jpg 300w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1505-768x576.jpg 768w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1505-640x480.jpg 640w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1505-48x36.jpg 48w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><br \/>\n<\/div>\n<div class=\"item\">\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1507-1024x768.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\" size-large wp-image-773\" srcset=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1507-1024x768.jpg 1024w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1507-300x225.jpg 300w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1507-768x576.jpg 768w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1507-640x480.jpg 640w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/IMG_1507-48x36.jpg 48w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><br \/>\n<\/div>\n<\/div><a class=\"left carousel-control\"  href=\"#custom-carousel-0\" data-slide=\"prev\"><span class=\"glyphicon glyphicon-chevron-left\"><\/span><\/a><a class=\"right carousel-control\" href=\"#custom-carousel-0\" data-slide=\"next\"><span class=\"glyphicon glyphicon-chevron-right\"><\/span><\/a><\/div>\n<p>The Year 2038 problem is a problem in which time values are stored as<br \/>\na signed 32-bit integer, and this number is interpreted as the number<br \/>\nof seconds since 00:00:00 UTC on 1 January 1970.  In such<br \/>\nimplementation, after 2038-01-19 03:14:07(UTC), the variable will<br \/>\noverflow and may cause system failure.<br \/>\nFor more, see <a href=\"https:\/\/en.wikipedia.org\/wiki\/Year_2038_problem\">wikipedia<\/a>.<\/p>\n<p>This device counts down the time to the moment that the year 2038<br \/>\noccurs. It continuously calibrates the internal RTC by accessing an<br \/>\nntp server.<\/p>\n<p>In this device, the year 2038 problem <em>do<\/em> take place.<\/p>\n<pre><code class=\"cpp\">      if (dispmode == MODE_UNIXTIME) {\n        dispDigits(now.unixtime()-SECONDS_UTC_TO_JST);\n      } else if (dispmode == MODE_COUNTDOWN) {\n        dispDigits((0x7FFFFFFF - (now.unixtime()-SECONDS_UTC_TO_JST))); \/\/ y 2038!\n      } else if (dispmode == MODE_CLOCK) {\n        dispClock(now);\n      } else if (dispmode == MODE_DATE) {\n        dispDate(now);\n      }\n<\/code><\/pre>\n<p><iframe loading=\"lazy\" title=\"7segment LED x 10 display clock (Demo the year 2038 problem) Failed ver.\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/hJBHb5ON73I?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>Just casting values in <code>dispDigits()<\/code> by <code>(int32_t)<\/code> makes things fine.<\/p>\n<p><iframe loading=\"lazy\" title=\"7segment LED x 10 display clock (Demo the year 2038 problem)\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/Mgxpzdlathw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h2>Materials<\/h2>\n<ul>\n<li>Micro controller: ESP-WROOM-02<\/li>\n<li>LED driver IC: HT16K33<\/li>\n<li>7 segment LED x 4: OSL40562-IB x 2 (anode common)<\/li>\n<li>7 segment LED x 1: OSL10561-IB x 2 (anode common)<\/li>\n<li>RTC: DS1307<\/li>\n<li>32kHz Crystal<\/li>\n<li>push switch (vertical)<\/li>\n<li>CR2032 battery holder<\/li>\n<li>PCA9306 I2C level converter<\/li>\n<li>Original PCB<\/li>\n<\/ul>\n<h2>Hardware<\/h2>\n<p>To say simply, this is a 10-digits 7-segment LED display with WiFi<br \/>\nconnection.<\/p>\n<h2>Software<\/h2>\n<p>I used Adafruit HT16K33 Arduino library (<code>Adafruit_LEDBackpack<\/code>) for<br \/>\ndriving 7 segment LEDs. However, this driver is written for<br \/>\ncathode-common LEDs. So I inherit the <code>Adafruit_LEDBackPack<\/code> class and<br \/>\nmodified display method for anode common LEDs (<code>Anodecommon_7seg<\/code>).<\/p>\n<p>The clock is always calibrated by ntp service and RTC with battery<br \/>\nstores time even if the power is not supplied.<\/p>\n<h3>API<\/h3>\n<p>This device provides HTTP service and REST API.<\/p>\n<table>\n<thead>\n<tr>\n<th>API<\/th>\n<th>parameter<\/th>\n<th>value<\/th>\n<th>effect<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>mode<\/td>\n<td>value<\/td>\n<td>int<\/td>\n<td>change mode<\/td>\n<\/tr>\n<tr>\n<td>status<\/td>\n<td>&#8212;<\/td>\n<td>&#8212;<\/td>\n<td>show status<\/td>\n<\/tr>\n<tr>\n<td>config<\/td>\n<td>timezone<\/td>\n<td>string<\/td>\n<td>change local timezone<\/td>\n<\/tr>\n<tr>\n<td>countdown<\/td>\n<td>date<\/td>\n<td>string<\/td>\n<td>set user-specified countdown timer<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>time<\/td>\n<td>string<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>timezone<\/td>\n<td>string<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code>$ curl http:\/\/esp_7seg.local\/status\n{\"unixtime\":1517957705,\"countdown\":629525942,\"mode\":0}\n\n$ curl \"http:\/\/esp_7seg.local\/mode?value=2\"\n{\"mode\":2}\n<\/code><\/pre>\n<h3>Web Interface<\/h3>\n<p>By accessing assigned URL (default: http:\/\/cc2038.local\/ ), you can use user-specified countdown feature easily.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-11-at-21.50.34-1024x705.png\" alt=\"\" width=\"640\" height=\"441\" class=\"alignnone size-large wp-image-789\" srcset=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-11-at-21.50.34-1024x705.png 1024w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-11-at-21.50.34-300x207.png 300w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-11-at-21.50.34-768x529.png 768w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-11-at-21.50.34-640x441.png 640w, https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-11-at-21.50.34-48x33.png 48w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>GitHub<\/h2>\n<p><script src=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-content\/plugins\/embed-extended\/assets\/js\/embed.js?ver=1.4.0\"><\/script><iframe loading=\"lazy\" class=\"ee-iframe\" sandbox=\"allow-scripts\" security=\"restricted\" src=\"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp\/wp-admin\/admin-ajax.php?action=embed_extended_iframe&#038;url=https:\/\/github.com\/omzn\/y2038_countdown.git#secret=660d11e931f8d\" title=\"GitHub - omzn\/y2038_countdown: A countdown clock for the year 2038 problem\" data-secret=\"660d11e931f8d\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" data-class=\"wp-embedded-content\"><\/iframe> <\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"entry-summary\" itemprop=\"text\">\n<p>https:\/\/youtu.be\/E-os8XCysBw?cc_load_policy=1&amp;rel=0&amp;autoplay=1 The Year 2038 problem is a problem in which time values are stored as a signed 32-bit integer, and this number is interpreted as the number of seconds since 00:00:00 UTC on 1 January 1970. In such implementation, after 2038-01-19 03:14:07(UTC), the variable will overflow and may cause system failure. For more, see wikipedia. This device counts down the time to the moment that the year 2038 occurs. It continuously calibrates the internal RTC by accessing an ntp server. In this device, the year 2038 problem do take place. if (dispmode == MODE_UNIXTIME) { dispDigits(now.unixtime()-SECONDS_UTC_TO_JST); } else if (dispmode == MODE_COUNTDOWN) { dispDigits((0x7FFFFFFF &#8211; (now.unixtime()-SECONDS_UTC_TO_JST))); \/\/ y 2038! } &#8230;<\/p>\n\n<\/div>\n","protected":false},"author":1,"featured_media":766,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"jetpack-portfolio-type":[19],"jetpack-portfolio-tag":[],"class_list":["post-764","jetpack-portfolio","type-jetpack-portfolio","status-publish","format-standard","has-post-thumbnail","hentry","jetpack-portfolio-type-products","entry-lead"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/jetpack-portfolio\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/jetpack-portfolio"}],"about":[{"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/types\/jetpack-portfolio"}],"author":[{"embeddable":true,"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/comments?post=764"}],"version-history":[{"count":17,"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/jetpack-portfolio\/764\/revisions"}],"predecessor-version":[{"id":793,"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/jetpack-portfolio\/764\/revisions\/793"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/media\/766"}],"wp:attachment":[{"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/media?parent=764"}],"wp:term":[{"taxonomy":"jetpack-portfolio-type","embeddable":true,"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/jetpack-portfolio-type?post=764"},{"taxonomy":"jetpack-portfolio-tag","embeddable":true,"href":"https:\/\/se.is.kit.ac.jp\/~o-mizuno\/wp-json\/wp\/v2\/jetpack-portfolio-tag?post=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}