Link a versión en español



Project of Remote Control for Intranet or Internet using the parallel port

by Daniel Solowiej

NOTICES: The project here exposed works perfectly in my environment of test and for my pretensions. Please check carefully the connections and polarities of your circuits before connecting them to the pc, because can be an irreversible damage. I do not become responsible for the correct functioning of the circuits and for the examples here explained. I decline any responsibility with regard to the enunciated and its consequences.

OBJET

Remote control of all kinds of electrical devices (general machines, lighting, robotics, engines, doors, managing of dangerous materials), for intranet or Internet using a browser and the parallel port of the pc.



INTRODUCTION

This project is born for the need to control distantly certain devices and machines, which must work for many hours in my workshop without human presence. But it's applicable to any electrical situation that deserves a control distantly, even from any place of the world by the Internet, needing in above mentioned, the logical adjustments for its functioning. As in my particular case, the necessary control is local (from the ground floor to the high floor of my house), only I will refer here to the implementation of a control for intranet, that for being logical and physically isolated of Internet or another Wan, it does not need the necessary attention to the traditional aspects of safety with regard to intrusions.

Though it's not raised here, it's easy to extend this project to functions of sensors without many modifications, using the five pines of state of the parallel port and enclosed port a card to increase the quantity of sensors.



DEVELOPMENT

I present here a scheme of the project.




In the most top part (in my case the workshop of the high floor), we have a pc that officiates as server (S), a router (R), an IP cam (C), and finally a driver for parallel port (D), in my case a buffer/driver that multiplies to 32, the 8 outputs pins of the parallel port.

In the lowest part (in my case the office of the ground floor) we see a pc client (L).



OPERATIVE SYSTEMS

Puppy Linux 3.01 retro in pc server. Puppy Linux 2.17 in pc client. Linux embebed into IP cam.



INTRANET

There was constructed with utp cable category 5 for exteriors. (Others it's to say that can be used Wifi or any another wireless or optical way). Length of the cable between client and router = 14 meters. Time I divide equally of the command Ping to the server = 0 ms / 0.5 ms

LAN composed by these ip addresses: 192.168.0.10 (pc server), 192.168.0.1 (router), 192.168.0.20 (Ip cam), 192.168.0.11 (pc client). I will not treat here like to form a domestic net neither in Puppy-Linux nor topics related to the recognition of the ethernet cards, and the load of the corresponding modules, provided that these topics have been extensively developed in the Forum of the above mentioned operative system and in his Wikki, for many colleagues, and they escape to the intention of this text.

http://www.murga-linux.com/puppy/

http://www.puppylinux.org/



WEB PAGES SERVER

Ghttpd, too simple and sufficient for this application. In case not It works correctly, the common solution is to kill all the processes httpd until none stays,

# killall httpd

and to modify the file of configuration, changing Localhost to any.

Then restart ghttpd. Check the sets of the firewall if it's necessary , in order that it allows the traffic.



PARALLEL PORT

Though one can use the onboard parallel port , always it is suitable to use a second parallel port for this type of functions. Provided that this Port has limitations with the current that it can support, it's necessary to have special and continuous care in everything related. In case of to use a PCI parallel port and to have problems to access it, I recommend to read my post in the Forum on an experience about it, and the friends replys there.

http://www.murga-linux.com/puppy/viewtopic.php?t=28686



DRIVER/BUFFER

In my case, I designed my own circuit, with some things of circuits found in the web, to be able to have 32 outputs of 12V, some with relays of exchanged exit, direct others (for stepping motors), and adding another card that meets down below, six exits of 220V exchanged.




This it's the graph of the circuit (without the leds):






Here we see the supplementary card to work exclusively with 220 volts. It has six income that connect to six of the exits of the buffer/driver, and have six exits exchanged (it's to say that they can be in use like normally opened or normally enclosure, duplicating this way the connections to twelve):






Finally to avoid the noises of line I used a parallel cable with filter Incorporated. This gives stability to the signals, still in places in which exist big modifications and peaks in the load of the electric lines, for what the activity of engines or lamps does not affect the solidity of the signals of the port.




/////////////////////////////////////////////////////////////////////

A circuit very easy to do:

To simplify here the things we think that it is perfectly possible to use a simple circuit as the following one, which allows to use the signals of D0 to D7 outputs of the port and to handle eight exits of 12V with a maximum intensity of 500 Ma, taking advantage of the integrated circuit ULN2803. It's always very advisable not welding directly integrated circuits to the card, is better to use socles. Of this way, we protect the integrated circuits of the temperature of the solder, and we can replace them easily, if they are burned.




/////////////////////////////////////////////////////////////////////



IP CAMERA (C)

I chose a camera with embebed server, because I use it for another domestic works. It simplifies enough the access by html to an image already engraved In the above mentioned server. In my case the route of the image is http://192.168.0.20/IMAGE.jpg - So it's simple to include the current path of the camera in an html frame using a tag like this:

<img src=”http://192.168.0.20/IMAGEZ.jpg”>

In case of Internet is in use, it's possible to send directly from the camera, the images by ftp and by e-mail.



HTML PAGES, SCRIPTS CGI

The interface presented to the pc client, is composed by web pages codified in html language, accessible by any browser. The pages are statics not dynamics, but they are updated with one automatic refresh placed in <head>.

The action to turn on a remote device is this :

1-The user does a click in the link "ON" of a certain equipment.

2-The link loads the shell-script cgi corresponding on this action in another frame giving in certain additional information.

3-The shell-script overwrite the image associated with the above mentioned device (red led ) with other one (green led), and it erases if exists, a file that symbolizes the state of "turn off" of the equipment, called " no + the number of equipment " . Leaving this information for the software reading.

The action to turn off a remote device is this:

1-The user does a click in the link "OFF" of a certain equipment.

2-The link loads the shell-script cgi corresponding on this action in another frame giving in certain additional information.

3-The shell-script overwrite the image associated with the above mentioned device (green led) with other one (red led), and creates a file that symbolizes the state of "turn off" of the equipment, called " no + the number of equipment ". Leaving this information for the software reading.

So as you see, the work of the CGI limits itself to overwrite files of images (support its names but not its content), and to erase or create a file that represents the states ON or OFF for every equipment. The files of image are those who allow to see the state of every equipment by the html code of the web page. The files that represent the "turn off" state of an equipment (that are not images) are alone used in order that the software understands that "OFF" state.

This it's a scheme simplified of the functioning:




Here is a real code of a cgi that I used in the project:

#!/bin/sh
cp htdocs/l.gif htdocs/leds/21.gif
rm htdocs/leds/no21





THE READING AND COMMAND SOFTWARE

Finally a software developed to the effect runs constant in a loop, reading the files " no + the number of equipment", by virtue of that realizes the binary corresponding calculation and do the final exit in bytes that must deliver to the parallel port (in decimal format). It's important to deactivate any program that puts in hibernation the pc server or that activates screen protectors or deactivates hard discs, of way that the reading and command software is not disturbed by these actions.

In my case I programmed a very simple console software using Freebasic.

The systems requirements are really low therefore the pc server can to be very ancient and there does not need Xserver to work. It's in alpha stage, but I put here the code for the one who wants to have one possible base of work.

You must think that it is writted to work with the Buffer/driver of 32 outputs, so that, if a simple circuit of eight outputs is used , the software will be also more simply.

#include "vbcompat.bi"

Dim shared addressport as integer

Dim shared filename As String

Dim shared binadeci as integer

Dim shared abi as integer

Dim shared abi1 as integer

Dim shared abi2 as integer

Dim shared abi3 as integer

Dim shared abi4 as integer

Dim shared abi5 as integer

Dim shared abi6 as integer

Dim shared abi7 as integer

Dim shared abi8 as integer

Declare sub inicio

Declare sub salidas

Declare sub enviar

Declare sub imagenes

Declare Function ioperm Cdecl Alias "ioperm" (Byval Portbase as integer,Byval nPorts as integer,Byval value as integer) As integer

addressport = &hde00

ioperm(addressport,5,1)

imagenes

inicio

salidas

'---------------------------------------------------------------

sub imagenes

shell "cp /root/ghttpd/htdocs/nol.gif /root/ghttpd/htdocs/leds/21.gif"

shell "cp /root/ghttpd/htdocs/nol.gif /root/ghttpd/htdocs/leds/22.gif"

shell "cp /root/ghttpd/htdocs/nol.gif /root/ghttpd/htdocs/leds/23.gif"

shell "cp /root/ghttpd/htdocs/nol.gif /root/ghttpd/htdocs/leds/24.gif"

shell "cp /root/ghttpd/htdocs/nol.gif /root/ghttpd/htdocs/leds/25.gif"

shell "cp /root/ghttpd/htdocs/nol.gif /root/ghttpd/htdocs/leds/26.gif"

shell "cp /root/ghttpd/htdocs/nol.gif /root/ghttpd/htdocs/leds/27.gif"

shell "cp /root/ghttpd/htdocs/nol.gif /root/ghttpd/htdocs/leds/28.gif"

shell "touch /root/ghttpd/htdocs/leds/no21"

shell "touch /root/ghttpd/htdocs/leds/no22"

shell "touch /root/ghttpd/htdocs/leds/no23"

shell "touch /root/ghttpd/htdocs/leds/no24"

shell "touch /root/ghttpd/htdocs/leds/no25"

shell "touch /root/ghttpd/htdocs/leds/no26"

shell "touch /root/ghttpd/htdocs/leds/no27"

shell "touch /root/ghttpd/htdocs/leds/no28"

sleep 20

return

end sub

'---------------------------------------------------------------

sub inicio 'setea variables a cero

cls

binadeci = 0

abi = 0

abi1 = 0

abi2 = 0

abi3 = 0

abi4 = 0

abi5 = 0

abi6 = 0

abi7 = 0

abi8 = 0

' inicializa puerto

out addressport, 0

sleep 10

out addressport+2, 4

sleep 10

out addressport+2, 11

sleep 10

end sub

'-----------------------------------------------------------------------------------------

sub salidas '-------------- rastrea imagenes de salida

do

filename = "/root/ghttpd/htdocs/leds/no21"

If FileExists( filename ) Then

abi1 = 0

else

abi1 = 00000001

end if

filename = "/root/ghttpd/htdocs/leds/no22"

If FileExists( filename ) Then

abi2 = 0

else

abi2 = 00000010

end if

filename = "/root/ghttpd/htdocs/leds/no23"

If FileExists( filename ) Then

abi3 = 0

else

abi3 = 00000100

end if

filename = "/root/ghttpd/htdocs/leds/no24"

If FileExists( filename ) Then

abi4 = 0

else

abi4 = 00001000

end if

filename = "/root/ghttpd/htdocs/leds/no25"

If FileExists( filename ) Then

abi5 = 0

else

abi5 = 00010000

end if

filename = "/root/ghttpd/htdocs/leds/no26"

If FileExists( filename ) Then

abi6 = 0

else

abi6 = 00100000

end if

filename = "/root/ghttpd/htdocs/leds/no27"

If FileExists( filename ) Then

abi7 = 0

else

abi7 = 01000000

end if

filename = "/root/ghttpd/htdocs/leds/no28"

If FileExists( filename ) Then

abi8 = 0

else

abi8 = 10000000

end if

' construye el binario final

abi = abi1 + abi2 + abi3 + abi4 + abi5 + abi6 + abi7 + abi8

binadeci = Val("&b" + Str(abi))

print "Enviando Binario " ; abi ; " al puerto paralelo - DECIMAL( " ; binadeci ; " )"

enviar

Loop until inkey = Chr(27)

' inicializa puerto

out addressport, 0

sleep 10

out addressport+2, 4

sleep 10

out addressport+2, 11

sleep 10

imagenes

print "Enviando Binario " ; abi ; " al puerto paralelo - DECIMAL( " ; binadeci ; " )"

print "Puerto Limpio"

print "Programa cerrado"

end sub

'----------------------------------------------------------------------------

sub enviar

out addressport, binadeci

sleep 10

out addressport+2, 9

sleep 10

out addressport+2, 11

sleep 50

return

end sub

'_____________________________________________________________





RUNING THE SERVICE

  1. Verify all the connections and its polarities before connecting the card to the pc.

  2. Switch off the pc, connect the card to parallel port.

  3. Start system of the router and expect to loads.

  4. Start system of the IP camera and expect to loads.

  5. Start system of the pc server. (If it is not necessary, not initiate Xserver or go out to prompt then, provided that this service does not need it working)

  6. Start server of web pages Ghttpd or the one that pleases.

  7. Start the "reading and command software".

  8. Turn off the monitor of pc server (Is not necessary to use it more).



Now you have everything to access from any pc client by browser and to use the service.