1) Introduction

If you are like most people you probably have and old desktop or laptop that technology has passed by. Perhaps it has a previous version of operating systems or like me a version or two back, they are hard to part with, far to much time and money went in to that machine to simply throw it out. With a little care, free software and Automation from www.BroadbandSentry.com these machines can be converted to monitor the Status of your home or office. These old machines (a new machine works as well) can be used to implement a home, office, and vacation home status monitor. In a previously article (Internet based Monitoring using low cost solutions. ) we discussed how to use off the shelf network hardware for a status monitor, in this article we will present a method to use a general purpose computer as a status monitor for use with www.BroadbandSentry.com.

www.BroadbandSentry.com monitors and alerts you to changes on the status monitor you create from this article. Your alerts are delivered using Email, SMS, MMS, and voice messages and are automatically generated based on your requirements.

2) Hardware Requirements

The computer you choose has a couple of basic requirements.

Operating System
Ethernet card
Parallel Printer Port
Display, Keyboard, and mouse for setup, once configured these are not required.

The speed of the computer is not a serious concern, old and slow is just fine.

3) Software required

We will be using Java, keep reading even if you have never used Java it really will be painless! First we need the Java SDK, it is available for down load at Java.Sun.com. The SDK we want is J2SE 1.4.2 SDK, I recommend downloading the offline installation version (write it to CD or a USB Memory). Installing the SDK is much like installing any other program, the defaults are fine, just keep clicking the next button. We are going to assume you will be using a Microsoft operating system, at http://java.sun.com/j2se/1.4.2/install-windows.html is the Installation notes for use with Microsoft Windows. An excellent tutorial has been written at http://javatrek.com/hints-java-setup.html. The Batch file example presented by javatrek.com ( http://javatrek.com/setenv.bat.txt ) is presented below with the minor change to the current version of the SDK done.

@echo off
rem use dos prompt properties to run
rem with Win98 set properties to run the batch file
rem with NT or 2000 set properties to run the batch file with /k switch
rem for example %SystemRoot%system32cmd.exe /k C:j2sdk1.4.0_01setenv
rem
rem ********************************************************************
rem * filename: setenv.bat Used to setup the Java build environment
rem * This file is provided free and without warranty “AS IS”.
rem * USE IT AT YOUR OWN RISK.
rem * NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
rem * WE MAY NOT BE HELD LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS
rem * OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.
rem ********************************************************************
rem
rem can optionally remove the lines beginning with rem
rem edit for the location of your JDK
set JAVA_HOME=C:j2sdk1.4.2_05 // (here?s the change)
rem edit other environment variables
rem set TOMCAT_HOME=C:tomcat
rem set CATALINA_HOME=C:tomcat
rem
rem edit for the location of jar files
set JARS=%TOMCAT_HOME%commonlibservlet.jar;
rem
rem ******* need PATH to find executables
rem do not have spaces on either side of the =
set PATH=.;%JAVA_HOME%bin;%PATH%
rem
rem ******* need CLASSPATH to find java code
rem do not have spaces on either side of the =
set CLASSPATH=.;%JARS%;
rem
rem ******* perform a sanity check
echo *** The PATH is
ECHO %PATH%
echo.
echo *** The CLASSPATH is
ECHO %CLASSPATH%
echo.
echo *** The JDK is
%JAVA_HOME%binjava -version
echo.

Note: javatrek.com suggest at the beginning of this file to use a batch file for NT, or 2000. I recommend that in NT, 2000, and XP one should set these variables using the control panel.

For Win98 copy and paste creating a batch file or copy into your autoexec.bat.

Because Windows in general attempts to isolate the hardware of the computer from user level programs we need one more building block to enable the reading of the Parallel port. Juan Gabriel Del Cid Portillo has written and placed on the web a very useful routine to access the Parallel Printer port via Java. His code is available at http://www.geocities.com/Juanga69/parport/, you need to download parport from http://www.geocities.com/Juanga69/parport/parport-win32.zip and follow the instructions. For Win98 users it is very simple, for NT, 2000 and XP users a second step is required as described in Juan Gabriel Del Cid Portillo documentation. The installation notes for parport do not call out the current SDK version, the correct directory to store the parport.ddl is C:j2sdk1.4.2_05bin.

3) Simple Http Server

The Simple Http Server uses the software services built into the Java SDk to build the HTTP server, and to get the real world status via the Parallel Printer Port we will use the parport support library.

The Simple Http server responds to a request from a browser, use the URL address: http://xxx.xxx.xxx.xxx:7170/ Note: the TCP/IP port number is required in the URL, with the following response:

Simple HTTP Server
Sat 2004.07.10 at 07:40:57 PM EDT
I/O port – Status:119
StatusByte< 01110111>

Be sure to substitute your machines IP address for xxx.xxx.xxx.xxx Depending on your home or office network configuration you may have a static or dynamic IP address assigned. We recommend you set up a static IP address in your Status Monitor Server.

The Date, time and the contents of the status register are returned. The :7170 is the port at which the server is lessening, the standard port address is 80 but is blocked some ISP?s as well should you have more then one server you may need to use port numbering to address them.

The Server code follows:

// HTTP Server

//***************************************

// ********************************************************************

// * This file is provided free and without warranty “AS IS”.

// * USE IT AT YOUR OWN RISK.

// * NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.

// * WE MAY NOT BE HELD LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS

// * OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.

// ********************************************************************

import java.net.*;

import java.io.*;

import java.util.*;

import java.lang.*;

import parport.ParallelPort;

import java.util.Date;

import java.util.Calendar;

import java.text.SimpleDateFormat;

import java.util.*;

public class httpServer_io

{

public static void main(String args[]) {

int port;

ServerSocket server_socket;

try {

port = Integer.parseInt(args[0]);

}

catch (Exception e) {

port = 7170;

}

try {

server_socket = new ServerSocket(port);

System.out.println(“httpServer running on port ” +

server_socket.getLocalPort());

// server infinite loop

while(true) {

Socket socket = server_socket.accept();

System.out.println(“New connection accepted ” +

socket.getInetAddress() +

“:” + socket.getPort());

// Construct handler to process the HTTP request message.

try {

httpRequestHandler request =

new httpRequestHandler(socket);

// Create a new thread to process the request.

Thread thread = new Thread(request);

// Start the thread.

thread.start();

}

catch(Exception e) {

System.out.println(e);

}

}

}

catch (IOException e) {

System.out.println(e);

}

}

}

class httpRequestHandler implements Runnable

{

final static String CRLF = “rn”;

Socket socket;

InputStream input;

OutputStream output;

BufferedReader br;

// Constructor

public httpRequestHandler(Socket socket) throws Exception

{

this.socket = socket;

this.input = socket.getInputStream();

this.output = socket.getOutputStream();

this.br =

new BufferedReader(new InputStreamReader(socket.getInputStream()));

}

// Implement the run() method of the Runnable interface.

public void run()

{

try {

processRequest();

}

catch(Exception e) {

System.out.println(e);

}

}

private void processRequest() throws Exception

{

while(true) {

String headerLine = br.readLine();

System.out.println(headerLine);

if(headerLine.equals(CRLF) || headerLine.equals(“”)) break;

StringTokenizer s = new StringTokenizer(headerLine);

String temp = s.nextToken();

if(temp.equals(“GET”)) {

ParallelPort lpt1 = new ParallelPort(0x378); // 0x378 is normally the base address for the LPT1 port

int aByte;

aByte = lpt1.read(); // read a byte from the port’s STATUS pins

System.out.println(“Input from parallel port: ” + aByte);

// Get today’s date

Calendar now = Calendar.getInstance();

SimpleDateFormat formatter = new SimpleDateFormat(“E yyyy.MM.dd ‘at’ hh:mm:ss a zzz”);

System.out.println(” It is now : ” + formatter.format(now.getTime()));

System.out.println();

// Construct the response message.

String serverLine = “Server: fpont simple java httpServer”;

String statusLine = null;

String contentTypeLine = null;

String entityBody = null;

String contentLengthLine = “error”;

statusLine = “HTTP/1.0 200 OK” + CRLF ;

System.out.println(“statusLine: “+statusLine);

contentTypeLine = “text/html” ;

entityBody = “” +

I/O port

+” Simple HTTP Server
“+formatter.format(now.getTime())

+”
I/O port – Status:”+aByte+”
StatusByte< "; int i = 256; //max number * 2 while( (i >>= 1) > 0) {

System.out.print(((aByte & i) != 0 ? “1” : “0”));

entityBody +=(((aByte & i) != 0 ? “1” : “0”));

}

entityBody += “>
“;

contentLengthLine = “Content-Length: ”

+ (new Integer(entityBody.length()).toString() )

+ CRLF;

// Send the status line.

output.write(statusLine.getBytes());

// Send the server line.

output.write(serverLine.getBytes());

// Send the content type line.

output.write(contentTypeLine.getBytes());

// Send the Content-Length

output.write(contentLengthLine.getBytes());

// Send a blank line to indicate the end of the header lines.

output.write(CRLF.getBytes());

System.out.println(“nentityBody: “+entityBody);

output.write(entityBody.getBytes());

}

}

try {

output.close();

br.close();

socket.close();

}

catch(Exception e) {}

}

}

Copy and Paste the above in to a file named ?c:httpserverhttpServer_io.java? . Only two commands are needed from here, one to compile and one to execute the Java code. Note: install parport as a subdirectory within c:httpserver.

Open a DOS window then:

Compile:
C:j2sdk1.4.2_05binjavac.exe ?deprecation ?g ?classpath c:httpserver httpServer_io.java

Next:

Execute the complied code:
E:j2sdk1.4.2_01jrebinjavaw.exe -classpath C:httpserver httpServer_io 7170

Now from your favorite web Browser ?http?//127.0.0.1:7170? will display:

Simple HTTP Server
Sat 2004.07.10 at 07:40:57 PM EDT
I/O port – Status:119
StatusByte< 01110111>

5) Connecting the Wires:

The Parallel port uses a 25 pin ?D? connector, we are reading the status bits only.

Bit 7

Pin 11

Busy

Bit 6

Pin 10

Ack

Bit 5

Pin 12

Paper out

Bit 4

Pin 17

Select In

Bit 3

Pin 15

Error

Bit 2

IRQ (not)

Bit 1

Reserved

Bit 0

Reserved

Pin?s 18-25 are grounds.

It is important to remember that these input pins are TTL!!! Only other TTL signals (+5V dc) or a switch or relay from one of the status bits to one of the grounds in the connector are allowed.

ANYTHING ELSE CAN CAUSE PERMANENT DAMAGE TO THE COMPUTER OR PERSONNEL !!!!!!!

For more information on interfacing to the Parallel port a quick web search will surface a very large number of useful sites. An excellent site is www.beyondlogic.org.

My previous article ?Internet based Monitoring using low cost solutions? Suggests a collection of ideas for interfacing to the TTL interface of an Ethernet enabled PrintServer. The ideas in that article are applicable here; your computer has exactly the same electrical interface.

Simple Temperature Sensor:

Simple Water Sensor:

6) Pulling it all together

This article presents a small Java program that reads the 5 status bits of the parallel port at lpt1 and presents them as a string of 1 & 0’s on a simple web page. You can use httpServer_io with www.BroadbandSentry.com which is web based service that you configure from your web browser. www.BroadbbandSentry.com works with the Web server you build in this article, off the shelf network hardware as described in our previous article, or any web enabled device. Messages can be generated by www.BroadbandSentry.com based on the content of Web pages. Email, SMS, MMS, and Voice messages can be generated by www.BroadbandSentry.com alerting you to important events at your home, vacation home or office, some examples are a simple temperature alert or water alert could be setup using the techniques from our previous article.

The following example show setting up three sensors; temperature, water and a door switch. Individual messages are defined for each sensor. Also note the overall device state of “no response”, a message can be generated should the httpSever be unreachable.

– Enabled 120832 / http://1.2.3.3:7170/ / … Delete this SentryPoint String not Found
Http_Server@ http://1.2.3.4 : 80 User: … Password: …
Frequency: 20 Minutes Add the update Frequency Add an Frequency
Times of operations: All times Enter the times of operation Enter the times of operation
HTTP request from IP address, .. Delete this event Add a State to this Function Add an State to this Function
String Found Delete this state Add a Action to this State Add an Action to this State
Find this sting: StatusByte< .1......>
Send Message Delete this action Customize this Action Customize this Action
gary_xx@zzz.com, Temperature low Delete this item Edit this Message Edit this Message

String Found Delete this state Add a Action to this State Add an Action to this State
Find this sting: StatusByte< ..0.....>
Send Message Delete this action Customize this Action Customize this Action
gary_xx@zzz.com, Water in basement Delete this item Edit this Message Edit this Message

String Found Delete this state Add a Action to this State Add an Action to this State
Find this sting: StatusByte< 0.......>
Send Message Delete this action Customize this Action Customize this Action
gary_xx@zzz.com, Power failed! Delete this item Edit this Message Edit this Message

This example uses the http web page, www.BroadbandSentry.com can also receive status updates via email, or UDP messages, and can check the health of network servers like email or application servers.

7) Network Security

The PC running this web server should at a minimum run a personnel firewall that blocks all but the port being used by the httpServer. The free version from ZoneAlarm (www.zonealarm.com) will work. In addition it is also a good practice to place a hardware firewall/router between your internal network and the modem connecting you to your ISP.

8) Conclusion

Using low cost personnel computer hardware as the building block for a web based sensor system is as shown above very straight forward. We started this article on the assumption that you might have an old computer to resurrect for this. But there are many sources of new low cost computers, major pc vendors and well as numerous catalog sales companies offer very affordable solutions. Remember for this application you do not need the fastest computer, just an affordable computer. There are numerous embedded solutions available, which can be used with www.BroadbandSentry.com. However for an individual using a low cost pc based systems is a very attractive solution.

A complete system based on this presentation would consist of an Internet connection, small pc, software as described and www.BroadbandSentry.com. This combination creates a user friendly, no software development, real world connected alert system. Using www.BroadbandSentry.com the web based service handles all the task of polling and notification.

BroadbandSentry is a trademark of C.S.D. inc. www.BroadbandSentry.com