Review: Decompiling Java

I just finished reading through Decompiling Java by Godfrey Nolan. You might ask, why would I mention a book on reverse-engineering bytecode in a weblog dedicated to smart buildings? What is the relationship between the intellectual property of companies writing Java code and home automation? The answer, essentially, is OSGi.

An OSGi framework, in a nutshell, is a Java program for managing and running other Java programs. When you start it you get a shell prompt that allows you to download, install, start, stop, upgrade and remove other Java programs delivered as bundles, i.e. compressed sets of files.

Since recent years it has become economically possible to have embedded controllers that run on stripped-down versions of Linux with specially designed Java Virtual Machines (JVM). In other words, it has become possible to run Java on these constrained targets. And Java is a good language for writing home automation systems. Indeed, according to Peter Kriens, the author of OSGi’s official weblog, OSGi was initially designed in 1998 for the home automation market.

I work together with Adhoco AG, whose flagship product is a home control system running an OSGi framework on an embedded controller. The author of the JVM we use has pointed out to us the relative ease with which compiled code can be decompiled, which is why I picked up this book after seeing it being reviewed in the ACM Computing Reviews.

Most of the book is about the process of decompilation itself, i.e. extracting the maximum amount of information from a compiled bytecode. While technically interesting, the meat of the book was in chapter 4, “Protecting Your Source: Strategies for Defeating Decompilers”.

That chapter will, I think, be the most interesting one for businesses and it is neatly summarized in a table at the end of the chapter. Protection strategies range from naive obfuscation (cheap to do, but provides weak protection) to the use of native methods for sensitive parts of the code (best protection in my opinion, but breaks portability).

I would not recommend the purchase of this book if all your business wanted to do was to protect yourself against decompilation. After all, about 90% of the book is concerned with the writing of a Java decompiler. You might be best served by borrowing this book from a library and reading chapter 4 instead. But if you want to know the internal workings of a Java classfile, then I am not sure where I would find a book with as much information as this one.

Vampires in the home

Referring again to the power consumption of “stand-by” appliances discussed earlier, I recently stoborrowed a WSE Wattmeter, made by Messtechnik Schaffhausen GmbH, from our laboratory, and measured the power consumption of the few appliances we have at our place after our recent move.

  • Sony stereo player: 6 W.
  • Aquarium, 60 L: 100 W with lighting turned on, 20 W with only filter, air pump and heater.
  • Philips TV: 8 W on standby, 130 W when turned on.
  • Philips DVD: not measurable on standby(!), 17 W when playing.

We have now decided to turn the TV completely off when not in use, which saves us 17.5 swiss francs per year. The Sony stereo can unfortunately not be turned off unless I install a mechanical switch.

I was rather surprised to learn that the lighting on our aquarium required about 80 W, when the fluorescent lamp was only rated at 15 W. I even went to a hardware store to buy a new one, only to discover that the power consumption did not improve. Then I realized that the 10+ years old ballast was almost certainly the culprit, accounting for the missing 65 W. That will be for the next visit to the hardware store…

Raclette machine control with X10

This Saturday I turned on our new raclette machine at our flat from my computer.

There is a fairly well-established home automation standard in the U.S. called X10, invented in 1975. It allows for the simple control of appliances, lights and other home equipment, using a communication protocol over the power lines.

It has however never been much popular here in Europe, and for a time I could never find a distributor of X10 equipment compatible with our swiss eletrical outlets. There is one however; on their website we europeans can finally find all the necessary equipment to carry out most of the hacks described in the book “Smart Home Hacks”.

I had our laboratory order some starter kits and elementary equipment in order to test things out. I will regularly post to this weblog updates on my tests and projects with this equipment; in the meantime, I would like to share my experience in setting up my computer to communicate with X10 from a Java program.

First I downloaded the software written by the Java X10 Project. This software includes useful examples to control simple appliances or lamps. However, it also needs an implementation of Sun’s Comm API, necessary for communicating over the serial interface.

I have had some very bad experiences with commercial implementations of this API so this time I tried out the open source RXTX implementation. You need to download the source and follow the INSTALL file scrupulously for this to work, including the contrib/ChangePackage.sh script. The compilation will look like it’s stuck in an endless loop but in fact it isn’t. Just be patient.

Once this was done, I could run the appliance example of the Java X10 project, which displayed a window with a single On/Off button. After making sure that my raclette machine was connected to an X10 applicance module with the right house and unit addresses, I clicked “On”, and heard the actuator switch on in the kitchen.

PS. If you are going to try this at home, make sure all the protective cellophane has been removed from your raclette machine first. I could switch the machine off in time to open the windows and ventilate before my wife could notice the heavy smoke. I guess no computer will ever completely prevent human errors. :-P

“Standby” appliances waste of energy

The BBC carries a story on the energy waste represented by household appliances kept on standby mode instead of being switched off. The UK alone wastes enough energy to send the population of Glasgow on a return flight to New York. The problem is that contrary to what most people (including me) believed, keeping an appliance on standby mode doesn’t save that much energy. From the article, some television sets run at about two-thirds consumption when on standby mode, rather than at just a fraction.

We’ve seen a similar problem in our lab. One of our printers, a Xerox Phaser 8200, used to be left on standby over the evenings and the weekends. Out of curiosity we once measured the printer’s consumption when under standby and found about 150 W, about the same amount of energy needed to keep two lightbulbs glowing. Let’s say nobody uses the printer between 6 pm and 8 am (14 hours), and you are left with a daily bill for about 2 kWh wasted. Under very optimistic assumptions, this is about the energy produced by two square meters of solar panels in Lausanne on a sunny day. Or to put it another way, at 11 swiss centimes per kWh during non-peak hours (roughly what we pay at our place in Geneva), it translates to 73 swiss francs per year.

Sure it irritates me to have to wait for warm-up when I send a print job to the printer in the morning. But if it were “my” money, would I pay that amount per year because I cannot wait for five minutes? Or because I cannot bring myself to remember to switch on the printer on when I arrive in the office? (The printer sits precisely on the way to my office.)

Update: I learned from some educational flyers in our institute that Europe requires the equivalent of six nuclear reactors just to keep devices on standby, or even switched off because of the inefficiency of some transformers.

Tools that anyone can use

I heard once a senior researcher criticize a doctoral student for having chosen a particular software tool to do his data analysis.

I was sitting on an International Energy Agency task meeting and the student (let’s call him Sam) was showing results from his analysis. Someone from the audience asked him what tool he had used for some of his intermediate results; when he replied awk, the senior researcher (let’s call him Max) went into a tirade against the use of anything else than Microsoft Excel when analyzing, saving and sending around data.

I would have had some respect for his opinion, if only he had not then given the main reason for his preference: “Everyone should use Excel, because it’s a program that secretaries know how to use.”

I firmly believe that in any craft, a good craftman will be defined by his choice and use of good tools. Excel, as a tool for scientific analysis, may in some restricted cases be doing a good job but suffers from several well-known deficiencies for me to use it on a daily basis.

But that is beside the point here. Max was not saying we should use Excel because it was good for the job; he said we should use it so that secretaries could open our files, display our results and include them in reports.

Has our profession grown so complacent that our work is now done by our support staff? What then is the work we, and we alone, as experts, are qualified to do? And whatever that work is, are we not free to evaluate and select the best tools for doing it, instead of allowing marketing pressures to guide our choices?

I hope this incident is an isolated one and that it does not reflect on our profession’s current best practices. Let us make sure it remains so.

Building Energy Software Tools Directory

The U.S. Department of Energy maintains on their website a fairly comprehensive directory of building energy software tools. From their website: “The energy tools listed in this directory include databases, spreadsheets, component and systems analyses, and whole-building energy performance simulation programs. A short description is provided for each tool along with other information including expertise required, users, audience, input, output, computer platforms, programming language, strengths, weaknesses, technical contact, and availability.” The directory can be found here
and includes, at the time of writing, information on 301 different software packages.

Eye movement tracking of office workers

Our laboratory hosted this morning a seminar given by Sylvia Hubalek, of the Environmental Ergonomics department of the Center for Organisational and Occupational Sciences in Zurich, Switzerland. She reported on work done by herself monitoring illuminance levels at the eye and tracking eye movements as a function of type of activity and light environment.

The data she gathers could help understand how feelings of well-being and alertness correlate with the amount of light we get during the day. Her methodology and equipement can also be used to understand what prompts people to switch their lights on/off, or raise/lower their blinds.

I learned about Sylvia’s work in September of this year at the LuxEuropa 2005 conference in Berlin. The head of our laboratory had been suggesting for some months that we try to set up an experiment where people would wear some equipment that would record their visual field somehow, and I had always dismissed the idea as too difficult to set up, and especially too difficult to find volunteers for.

Well here came Sylvia and proved me all wrong. Her contribution to the conference can be found here. She fits volunteers with equipment and records data for entire days.

It is too early for her to announce some specific findings, but what she does have is a substantial amount of data waiting to be analyzed. Results should be forthcoming in the next year.

We have in our lab some experience with monitoring people’s behaviour with respect to their visual environment, and a natural collaboration between Sylvia’s institute and ours would be to record data with her equipment while we monitor the subject’s acivities. This will help us achieve a much better understanding of what constitutes visual comfort and discomfort, and will also help us develop better automatic daylight controllers.

Welcome to the Computing & Smart Buildings blog

Welcome to the Computing & Smart Buildings blog. In this column I will provide insights on a regular basis on how computers in all their forms are used to make the home or the office a more comfortable place to live, or how they are used in the field of building research.