Tuesday, August 04, 2015

Raspberry Pi - adventures in home automation (h/w and s/w)

I kicked off a project some time ago around a Raspberry Pi to perform some home automation - namely to control my backyard sprinkler system. The old system got relocated during some backyard updates and the original wiring and system had seen better days so I decided to replace the old 1980's unit and wiring with a Raspberry Pi based set up.

Needless to say, I've had a pile of electronics sitting on my office desk for some months (ie what happens when done in dribs and drabs!) but it has been fun assembling pieces of kit to get this thing working.

The basic objective is to create a circuit controlled by the Raspberry Pi to manage standard 24VAC sprinkler valves attached to a residential pressure water supply. The Pi will run an app server to host the device control software and will respond to commands from a web browser based UI. It will need to have some safety features built in to ensure the system turns off the sprinklers on failure!

So far, I have in terms of h/w inventory (circuit diagrams and photos to follow in a separate post):
  • Raspberry Pi Model B+
  • WiFi USB dongle
  • 4 Relay module
  • 24VAC step down transformer
  • Some wiring (raw wires and header pin leads)
We're at the conceptual stage but have shown that the relay board can be triggered via the Pi's GPIO array which is the foundation for starting on the control software.

In terms of software, I have the following:
  • WiringPi utility (for initial testing with the Pi's GPIO interface)
  • pi4j library (which I later discovered and found and makes more sense to use from Java than executing external processes such as the gpio utility from WiringPi - CGI, anyone???)
  • glassfish J2EE app server (for running the control software)
  • NetBeans IDE running on Win7 for development
I basically followed the directions here to get the Pi set up to run the glassfish server. As the main points of difference I created a user 'glassfish' to run the server rather than the pi account itself and I loaded the glassfish 4.1 full server, not the web profile. It takes some minutes to start up, even with the Pi overclocked to 950MHz. Maybe the web profile version is lighter weight but I haven't tried it.

You will need to set up NetBeans to be able to see your glassfish app server on the Pi. Do this under the Tools->Servers menu in the NetBeans IDE. You should see the server under Services->Servers. The next thing to do is get your project to use the remote server explicitly by right clicking your NetBeans project, selecting 'Properties' at the bottom of the menu then selecting from the category tree on the left 'Run', then select the server you created. This will run a lot slower than your desktop app server (say 20+secs for a deployment) but we'll have to live with this to get access to some of the Pi h/w and utilities such as WiringPi/pi4j which won't be available on the default local app server on your dev box.

To use the pi4j library in your dev environment you will need to make the library available to the NetBeans IDE. I am new to this IDE so in the event you are too then under the Projects tab look in the tree for Libraries then Add JAR/Folder... then use the file system browser to select the pi4j-core.jar file and similarly the pi4j-core-javadoc.jar and pi4j-core-sources.jar files. The latter will help some context menus to work in the IDE should you for example want to see javadoc for pi4j.

To run the pi4j code in your test/runtime environment you'll need to make it available to your app server - in this case the glassfish app server. To do this I fired up the glassfish admin server on the Pi (ie 192.168.1.x:4848) after following the installation instructions for the Raspberry Pi on the pi4j link above. Remember that glassfish on the Pi isn't speedy. Also, I found the admin console didn't work with Chrome Version 44.0.2403.125 m but works ok with IE11. Go figure. Chrome shows a message about detecting a long running process then the page never displays. IE11 shows the same message, but eventually displays the page.

You can find the glassfish server reference manual here but in short this is what I ran to load the 3rd party pi4j libary into the Pi's glassfish app server instance. Adjust paths for your system accordingly.

glassfish@raspberrypi001 /opt/glassfish/glassfish4/bin $ ./asadmin add-library --type ext /opt/pi4j/lib/pi4j-core.jar
Enter admin user name: admin
Enter admin password for user "admin":
Command add-library executed successfully.



The add-library command requires a restart of the server so do that now:
glassfish@raspberrypi001 /opt/glassfish/glassfish4/bin $ ./asadmin start-domain domain1
Waiting for domain1 to start ........................................................................
Successfully started the domain : domain1

We may later find that additional libraries are required - there are three other JARs in the pi4j directory.

Anyway, this is about what I've discovered around setting up the development and test environments to date. I will come back with any edits or updates here, or cross link to new posts as further progress is made.

No comments:

Post a Comment