Advertisment

Remote Control Devices Overthe Net

author-image
PCQ Bureau
New Update

Last December PCQuest had published an article called Make your Own Robot (page 44, December 2002). It talked about building a toy car robot and controlling it using a PC’s parallel port. Many of you would have experimented with it. I did, too.

Advertisment

In fact, I controlled a light bulb using a C program. This article is as an extension of the Make your Own Robot article, and here we talk about controlling your electrical/electronic equipment from anywhere in the world.

What you need



Creating this project is not very expensive and would cost perhaps a few hundred rupees. Here’s what you should have and know before starting with this experiment. 

l Working knowledge of the Internet



l An understanding of IP addressing


l Working knowledge of Web servers (IIS/PWS/Apache)


l Some amount of VB and database programming skills


l Server-side scripting (ASP or equivalent) involving a database


l Basic electronics knowledge to construct the parallel port interface circuit



Advertisment

I am not going to give you the actual source code for this experiment; only the concepts and methodologies. You need to create three application programs: a Web-oriented server-side application, a C program for generating the potential difference on the parallel port pins of your computer, and a VB application that will always run in the system tray of your Web server.

You’ll also need to create a small database using any database server. We insist on using a server-edition database as it would assist your server-side scripting and help create a three-tier architecture. We used MySQL Server for the job. The database structure should be as follows:

TableName: edevice



Fields:


Name: Status 


Type: Number(1)

Advertisment

Building the system



First build the system according to the details given in the Make your Own Robot article. Here’s a quick overview of the same: 

l Create two .exe files using a C++ compiler and call them on.exe and off.exe, where the filenames reveal their analogous functions. Use outportb() function by including dos.h in your program. The sample source code is given in the Make your Own Robot article under the heading Basic Control. Construct the circuit as shown in figure. 



l Connect the interface circuit to the parallel port of your PC. Do remember to use only Windows 9X because parallel port programming is not supported in NT.


l Connect any electrical device to your interface circuit and test it by running on.exe and
off.exe. 

Server-side scripting



We used ASP to create the server-side application and Personal Web Server in Windows 98. Create a database-oriented Web application to update the database you created above. Add to your index page two buttons captioned as follows.

Advertisment

Button B1 captioned as “Switch ON Fan”



Button B2 captioned as “Switch OFF Fan”

Now add scripts to these two buttons such that:



On B1’s Click event:


Make the value of field Status in table edevice to “1”


On B2’s Click event:


Make the value of field: Status in table: edevice to “0”. 


Publish the application in \inetpub\wwwroot\edevice and test it by firing up your Web browser and entering http://127.0.0.1/edevice in address bar.



The second application is equally important and we used VB 6.0 to develop it. This application should always run in the system tray of the computer running your Web server. It’s needed when this machine connects to the Internet. The application is based on a Timer routine, so include two Timer controls in a VB form. Here’s the algorithm you need to user for creating these timers. First set Timer interval to 2000 so that it triggers for every two seconds.

Advertisment

a. Timer1 algorithm: 






if( val(status) in edevice table==1)


{


shell “c:\on.exe”


Timer2.enabled=true


Timer1.enabled=false


exit sub


}


}


b. Timer2 algorithm: 





if( val(status) in edevice table==0)


{


shell “c:\off.exe”


Timer1.enabled=true 


Timer2.enabled=false


exit sub


}


}

















The working principle



The way these timers work is pretty simple–just like a relay switch, except that this is done in software. You create a Web page that can change the value of field “status” in table “edevice” to either “1” or “0”. The second application will check every two seconds for the value of field “status” in the database. There are two timers in the application, which assume that initially the device is switched off (the value of “status” in database is “0”). So, initially both timers are executed concurrently. As the value of status is 0, Timer2 will execute off.exe. Since the device is already in “off” state, there won’t be any impact. Timer2 will disable itself and exist, and Timer1 will be running alone. It checks every 2 seconds whether the value of status is set to 1. 

Now open your browser and type http://127.0.0.1/edevice and click “Switch On” button. On clicking this button the value of status in database should be set to 1. Timer1 finds the value to be “1” and enters the “if” loop. There it runs on.exe to subsequently turn your electrical device on. After this, Timer1 is disabled and Timer2 starts running. It constantly checks for the database value to see if it’s 0.

Advertisment

The Shell command in Visual Basic is used to run a Windows/DOS executable file from the visual basic application. 

Last words



Since the control is through the Web browser, this application can be run from anywhere. Whether you run it on your network or from the Internet, you need to give a fixed IP address to the machine running your Web server and the VB application. This might be a problem if you’re experimenting on a home machine that connects using a dial-up account. That’s because your IP address will keep changing. For this, you could look at a service like dns2go, which keeps the domain name consistent for sites with a dynamic IP address. This service used to be free, but is now available at a price. Alternately, you’ll need somebody on the machine to check the IP address and inform others who want to access it over the Internet. If you’re running this on a home machine, then you may want to add an authentication page for users to access this system. Plus, a firewall is a must to prevent unauthorized users from accessing your system. 

Suresh Babu M

Advertisment