Using a Kindle as an eInk Clock (Java)

Earlier on today I used Python (via Flask, some HTML and my Raspberry Pi) to help turn my Amazon Kindle into an eInk digital clock. This was cool and I was happy until I decided I wanted to do the same thing via Java and TomCat.

geektechstuff_time_java_jsp
A Java JSP to show the time

For this project I am using:

  • A Raspberry Pi 3 as my web server
  • Apache Tom Cat to serve the JSP file
  • A Java JSP file
  • A very basic CSS file to control the font size
  • An Amazon Kindle

A .jsp file is a Java Server Page file and contains static material (e.g. text / HTML) and dynamic content (in this case the time). The <%@ tag is used to describe what the file contains and any Java libraries that need importing. The <% tag is where dynamic content is used. As with my earlier Python/Flask version I am using a CSS file to control style and a http refresh command to force the page to refresh.

More information on JSP files can be read at https://en.wikipedia.org/wiki/JavaServer_Pages

The time.jsp contains the following:

<%@ page language=”java” contentType=”text/html”%>
<%@ page import=”java.text.*,java.util.*” %>
<html>
<head>
<title>GeekTechStuff Time</title>
<link rel=”stylesheet” type=”text/css” media=”screen” href=”main.css”>
<meta http-equiv=”refresh” content=”30″>
</head>
<% SimpleDateFormat sdf=new SimpleDateFormat(“HH:mm”); %>
<body>
<h1><%= sdf.format(new Date())%></h1>
</body>
</html>

The main.css contains the following:

h1 {
color: black;
text-align: center;
font-size:108pt;
}

Both the time.jsp file and the main.css file are stored in the /webapps/ROOT/ folder of my TomCat set up. For my set up this location was at:

/var/lib/tomcat8/webapps/ROOT

geektechstuff_time_java_jsp_1
Java JSP showing the time

As with the Python version there is some inaccuracy as the page auto refreshes every 30 seconds, this can be edited to a small refresh but this will mean the eInk screen is used more.

Java eInk digital clock
Java eInk digital clock

Welcome to GeekTechStuff

my home away from home and where I will be sharing my adventures in the world of technology and all things geek.

The technology subjects have varied over the years from Python code to handle ciphers and Pig Latin, to IoT sensors in Azure and Python handling Bluetooth, to Ansible and Terraform and material around DevOps.

Let’s connect