//enterprise java /
Wake Up and Smell the Coffee
The creators of jHome, a 2011 Duke’s Choice Award winner, demonstrate why Java EE 6 development is so easy.
lights from their mobile devices.
The possibilities for simplifying
the way you control the objects in
your life are unlimited.
JAVA IN ACTION
VINICIUS SENGER AND
YARA SENGER
jHome is a complete home- automation open source API
based on GlassFish Server Open
Source Edition and Java EE 6,
which enables developers to control anything in their homes.
In this article, we describe the
jHome project in detail, including
the technical context, code, and
hardware details. Usage examples
show the power and ease of use of
Java EE.
Like most Java programmers,
we are crazy for coffee. We always
wanted to schedule our coffee
maker to turn on at a certain time,
so we could wake up to the smell
of coffee. So we set out to develop
a way to do this. After all, nothing
is more fun than using the Java EE
6 Timer Service to schedule the
“real objects” of your life.
People who always lose or forget their keys, for instance, might
want to control their front door
through a Website or a mobile
application. And why not open
your door by sending a message
to a Twitter profile that is associated with your jHome application?
Others might want to control their
balcony lights or swimming pool
jHome Overview
jHome is a set of interfaces and
components based on Java EE 6
for implementing home-automation solutions. Using
Enterprise JavaBeans (EJB), the
Timer Service, Java API for RESTful
Web Services (JAX-RS), Contexts
and Dependency Injection (CDI),
and Web components, jHome lets
you automate your house, build
a Web or mobile app, and control
things over the internet.
Figure 1 shows an overview of
the jHome architecture.
With the simple code shown in
Listing 1, you can inject an object
that represents a lamp in your
house and turn it on or off using
a Servlet.
Using EJB beans to control a
lamp may sound strange, but
the Singleton, Transactions, and
Injections resources are a very
useful way to deal with hardware
communication, concurrency, and
queuing requests.
jHome Devices
jHome is based on open source
hardware and does not require
proprietary or expensive solutions. The jHome team created
the reference implementation
hardware based on Arduino, an
open source electronics prototyping platform. The cost to control
two lamps or wall sockets is less
than US$100 using Arduino and
USB cables.
Each jHome device can communicate with the jHome application deployed on the Java EE
container using different protocols and different wired and wireless components:
■ ■ USB cable (the cheapest
solution)
■ ■ Bluetooth (good for wireless
prototypes)
■ ■ ZigBee/xBee (the best
wireless solution for real
implementations)
Relay boards are very useful
because they let you control wall
sockets, lamps, and any other electronic device. jHome can also read
values from sensors such as temperature, light, distance, and gas.
The standard firmware for
jHome devices can control relays,
dimmers, RGB LEDs, motors, and
robots, and code for various sensors is available at the Tools Cloud
ABOUT US
blog
Figure 1