Coding A Machine Readable Clock (qrtime.com replica)

Earlier I’ve seen this Robot Readable clock and I was impressed by its simple ingenuity and so I decided to build something similar to it, basically what I had in mind was a website that displayed time in QR code and refreshed often enough to keep the QR code current, I’d then get a spare netbook, run this code and attach it to an old LCD I’ve (old ones are quite cheap), even though not as elegant it’ll still serve the same purpose.

Not knowing that something like that already existed (qrtime.com) I set out to build it on my test LAMP server, basically I relied on google charts liberary to generate the QR code and a javascript auto refresh bit and in no time I had a website that displays time in QR code.

As you see in the code, there is an auto-refreshing java script embedded in the page, and a php script that communicates your machine time to Google charts API and displays the image that’s returned (I used “str_replace” to convert spaces into %20). this is the second time I use google charts api and I believe that its nothing short of a God send.

Timenow.php

<html>
 <head><script language="javascript" type="text/javascript">setTimeout("location.reload();",5000);</script>
 <title>Current Time Now Is</title>
 </head>
 <body>
 <center><b><br><br><br>
 <?php
 $t= strftime('%c');
//echo $t;
$b = str_replace(" ","%20", $t);
$t='<img src=https://chart.googleapis.com/chart?cht=qr&chs=450x450&chl='.$b.'&choe=UTF-8>';
echo $t;
 ?>
 </b></center>
 </body>
 </html>

—UPDATE—
I deployed the same concept on google appengine, worked like a charm, completely free and it have the added feature is that the time is queried from the server rather than the client (which beats the concept of having an online clock), anyway check the link and I hope you like it.

 

http://test1bmt.appspot.com/guestbook

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s