Simple CGI-BIN controlling example
สิงหาคม 16, 2010 ใส่ความเห็น
Simple CGI-BIN controlling example
In this example the idea is that you make a web page that has the control buttons what controls you want to do. The control buttons are set so that pressing them causes user web browser to send the form contents to a CGI-BIN script. This call causes the web server to run the specified CGI-BIN script. The CGI-BIN scrips is written to perform the needed controlling, typically calling the parallel port controlling program with right parameters.
This is the basic idea how to do this.
Here is a simple example web controlling application. Do the following to make it work:
1. Make sure that your system is running Apache web server. Most modern Linux distributions come already with this web server software. Make sure you have Apache installed. The flllowing steps expect that you run Linux system with correctly configured Apache (Red Hat 7.2 Linux default setting are OK). I epect that the web pages related material is located in /var/www/ directory (this is typical place on Red Hat Linux systems, on other distributions the place can vary, change the examples in this case as needed). Make sure that your web server is running. You can start is it for example with following command (in most systems you need to be root to do this):
/sbin/service httpd start
Make sure you can access your Linux computer with your web browser (running on the same or other computer) when Apache is running on the Linux computer.
2. Compile the lptout.c source code to lptout binary program, copy the pgoram to /usr/sbin/ directory and set rights so that it is always executed as root. You can do this by logging on as root and executing the following commands:
gcc -O lptout.c -o lptout.c cp lptout /usr/sbin/lptout chmod +s /usr/sbin/lptout
This shoud do this. Now everybody should be able run the command. Test this by logging in as somebody else than root and excute the command:
This should turn on all parallel port LPT1 data pins high (3..5V). Executing command
should turn all output pins low (0..1V). Make sure that this works without problems. Test that the port gets really controlled with this program with a multimeter or the LED circuit decribed in the beginning of this document.
3. Install the CGI scripts for parallel port controlling. The need scripts are lpton.cgi and lptoff.cgi. Click the file names to see the source code, use “view source” if needed, save those files to your system with names lpton.cgi and lptoff.cgi. Then copy those files to the web server CGI-BIN directory and give necessary executing rights. Log in as root and do the following commands on the diectory where you stored the lpton.cgi and lptoff.cgi:
cp lpton.cgi /var/www/cgi-bin/lpton.cgi cp lptoff.cgi /var/www/cgi-bin/lptoff.cgi chmod go+rx /var/www/cgi-bin/lpton.cgi chmod go+rx /var/www/cgi-bin/lptoff.cgi
4. Install the necessary controlling web page. In this example your controllign webpage resides in the web address http://www.epanorama.net/counter.php?url=http://yourservernamehere/lpt/index.html where the “yourservernamehere” means the name or IP address of your Linux computer you run this application at. You need the web page index.html source code (click filename to see the source code, use “view source” if needed ,save to your computer as index.html file). To create the web directory for the parallel port controlling do the following when logged as root:
cd /var/www/html/ mkdir lpt chmod go+rx lpt
Now go to the directory where you have the index.html file and copy it to the created directory with following commands (still logged in as root)
cp index.html /var/www/html/lpt/index.html chmod go+r /var/www/html/lpt/index.html
5. Test that you can access the controlling page on the Linux server. Point your web browser to addewss http://www.epanorama.net/counter.php?url=http://yourservernamehere/lpt/index.html where the “yourservernamehere” means the name or IP address of your Linux computer. You should see a controlling page that looks something like this:
6. Test pressing the control buttons and see that the paralle port output pins change their state as controlled.
You can find all the necessary files for this simple web project at one tar file called weblpt.tar. Just download it to your Linux system and expand it to suitable directory with command
tar xvf weblpt.tar
Now you have all the files you need. Just do the steps needed with them and you should get your simple web controlling application working well.
NOTE: This a simple example of parallel port controlling through web. This example is proably not the most convient or efficent way to do the controlling, but has worked for me. When making electronics that is controlled through web, you need to always think of the information security related to this, meaning that only people whos shoudl be able to do the controlling can do this and nobody can easily hack to your system. This method has potanetial security risks because the lptout program is always run at root rights (if somebody can make it to crash somehow this can potentially cause security problems). To do all the steps mentioned in this document you need to be logged as root to the system to do what is needed, when you are as root, you can do lots of harm to your system if you do stupid mistakes.