This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:jr018429:portfolio:first_hpc_2_eoce_0x1_preparation [2011/05/18 16:42] – [Procedure] jr018429 | user:jr018429:portfolio:first_hpc_2_eoce_0x1_preparation [2011/05/19 00:05] (current) – [Procedure] jr018429 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP centeralign round graybg box 96%> | ||
+ | <WRAP muchbigger> | ||
+ | <WRAP bigger> | ||
+ | </ | ||
+ | ======Objective====== | ||
+ | The object of this project is to create Arduino and CGI applications that will be used in combination to monitor sensors and use the returned data to control a process over the World Wide Web. | ||
+ | ======Materials/ | ||
+ | ^Description^Quantity^Price^URL or Model #^ | ||
+ | |float switches|2|$6.99|http:// | ||
+ | |tubing adapters|2|$1.00|http:// | ||
+ | |mold-a-holder|2|$3.95|http:// | ||
+ | |crimp caps|1|$1.99|http:// | ||
+ | |Solid state relay|1|priceless|Continental Industries S505-OSJ210-000| | ||
+ | |Computer with Linux Debian and Apache 2 Web Server|priceless|see Linux install and Apache 2 install projects|-| | ||
+ | |||
+ | |||
+ | |||
+ | ======Background====== | ||
+ | Web servers use the client/ | ||
+ | There are many protocols used for different purposes across the Internet for example, HTTP-Hypertext Transfer Protocol, FTP-File Transfer Protocol, and HTTPS-Secure HTTP. The communication protocol used to request and serve unsecure Web pages is HTTP. As we learned in our networking fundamentals course, the well known port for HTTP is port 80. So a Web server listens at port 80 (usually) for a request from a Web client.\\ | ||
+ | \\ | ||
+ | CGI is a specification for transferring information between a Web server and a CGI program. A CGI program is any program designed to accept and return data that follows the CGI specification. A CGI program could be written in any one of a number of programming and scripting languages. | ||
+ | In order for the scripts or programs to be executed, a Web server must be installed. Next, the file or files to be executed must be in a specific directory on the Web server. The CGI program can then be executed by including the bin-cgi directory and filename in the URL, for example: http:// | ||
+ | |||
+ | Arduino is an open-source electronics prototyping platform based on AVR microcontrollers and ICs which make communications between an Arduino and other platforms very easy to implement, for example the FTDI USB serial IC and driver. | ||
+ | ======Procedure====== | ||
+ | **1. Install the Arduino IDE on a computer**\\ | ||
+ | Start the Arduino install by following the instructions on the following Web page: http:// | ||
+ | Preparation for the Arduino IDE installation: | ||
+ | <cli> | ||
+ | bob@dhcp-179: | ||
+ | Password: | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | binutils-avr ca-certificates-java icedtea-6-jre-cacao java-common | ||
+ | libaccess-bridge-java libaccess-bridge-java-jni openjdk-6-jre-headless | ||
+ | openjdk-6-jre-lib tzdata-java | ||
+ | Suggested packages: | ||
+ | avrdude-doc task-c-devel gcc-doc gcc-4.2 default-jre equivs icedtea6-plugin | ||
+ | sun-java6-fonts ttf-baekmuk ttf-unfonts ttf-unfonts-core ttf-sazanami-gothic | ||
+ | ttf-kochi-gothic ttf-sazanami-mincho ttf-kochi-mincho ttf-wqy-microhei | ||
+ | ttf-wqy-zenhei ttf-indic-fonts | ||
+ | The following NEW packages will be installed: | ||
+ | avr-libc avrdude binutils-avr ca-certificates-java gcc-avr | ||
+ | icedtea-6-jre-cacao java-common libaccess-bridge-java | ||
+ | libaccess-bridge-java-jni openjdk-6-jre openjdk-6-jre-headless | ||
+ | openjdk-6-jre-lib tzdata-java | ||
+ | 0 upgraded, 13 newly installed, 0 to remove and 12 not upgraded. | ||
+ | Need to get 49.7 MB of archives. | ||
+ | After this operation, 149 MB of additional disk space will be used. | ||
+ | Do you want to continue [Y/n]? y | ||
+ | Get:1 http:// | ||
+ | Get:2 http:// | ||
+ | Get:3 http:// | ||
+ | Get:4 http:// | ||
+ | Get:5 http:// | ||
+ | Get:6 http:// | ||
+ | Get:7 http:// | ||
+ | Get:8 http:// | ||
+ | Get:9 http:// | ||
+ | Get:10 http:// | ||
+ | Get:11 http:// | ||
+ | Get:12 http:// | ||
+ | Get:13 http:// | ||
+ | Fetched 49.7 MB in 2min 4s (400 kB/s) | ||
+ | Selecting previously deselected package java-common. | ||
+ | (Reading database ... 128528 files and directories currently installed.) | ||
+ | Unpacking java-common (from .../ | ||
+ | Selecting previously deselected package openjdk-6-jre-lib. | ||
+ | Unpacking openjdk-6-jre-lib (from .../ | ||
+ | Selecting previously deselected package ca-certificates-java. | ||
+ | Unpacking ca-certificates-java (from .../ | ||
+ | Selecting previously deselected package tzdata-java. | ||
+ | Unpacking tzdata-java (from .../ | ||
+ | Selecting previously deselected package openjdk-6-jre-headless. | ||
+ | Unpacking openjdk-6-jre-headless (from .../ | ||
+ | Selecting previously deselected package libaccess-bridge-java-jni. | ||
+ | Unpacking libaccess-bridge-java-jni (from .../ | ||
+ | Selecting previously deselected package openjdk-6-jre. | ||
+ | Unpacking openjdk-6-jre (from .../ | ||
+ | Selecting previously deselected package libaccess-bridge-java. | ||
+ | Unpacking libaccess-bridge-java (from .../ | ||
+ | Selecting previously deselected package binutils-avr. | ||
+ | Unpacking binutils-avr (from .../ | ||
+ | Selecting previously deselected package gcc-avr. | ||
+ | Unpacking gcc-avr (from .../ | ||
+ | Selecting previously deselected package avr-libc. | ||
+ | Unpacking avr-libc (from .../ | ||
+ | Selecting previously deselected package avrdude. | ||
+ | Unpacking avrdude (from .../ | ||
+ | Selecting previously deselected package icedtea-6-jre-cacao. | ||
+ | Unpacking icedtea-6-jre-cacao (from .../ | ||
+ | Processing triggers for man-db ... | ||
+ | Processing triggers for desktop-file-utils ... | ||
+ | Processing triggers for gnome-menus ... | ||
+ | Processing triggers for menu ... | ||
+ | Processing triggers for hicolor-icon-theme ... | ||
+ | Setting up java-common (0.40) ... | ||
+ | Setting up tzdata-java (2011c-0squeeze1) ... | ||
+ | Setting up binutils-avr (2.20.1-1) ... | ||
+ | Setting up gcc-avr (1:4.3.5-1) ... | ||
+ | Setting up avr-libc (1:1.6.8-2) ... | ||
+ | Setting up avrdude (5.10-3) ... | ||
+ | Setting up openjdk-6-jre-lib (6b18-1.8.3-2+squeeze1) ... | ||
+ | Setting up openjdk-6-jre-headless (6b18-1.8.3-2+squeeze1) ... | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | Setting up libaccess-bridge-java (1.26.2-5) ... | ||
+ | Setting up libaccess-bridge-java-jni (1.26.2-5) ... | ||
+ | Setting up icedtea-6-jre-cacao (6b18-1.8.3-2+squeeze1) ... | ||
+ | Setting up ca-certificates-java (20100412) ... | ||
+ | creating / | ||
+ | done. | ||
+ | Setting up openjdk-6-jre (6b18-1.8.3-2+squeeze1) ... | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | update-alternatives: | ||
+ | Processing triggers for menu ... | ||
+ | root@dhcp-179:/ | ||
+ | </ | ||
+ | - After performing these steps, install the Linux 32-bit version of the Arduino IDE software which can be downloaded from the following Web page: http:// | ||
+ | - Using an appropriate power converter, plug the Arduino end of the power converter into the Arduino Duemilanove and outlet end into a wall outlet. | ||
+ | - Using an appropriate USB cable, plug the Arduino end into the Arduino, and the USB end into a USB port on the target computer. | ||
+ | - Move the downloaded file to the Desktop directory. | ||
+ | - Next, right-click on the file and selected " | ||
+ | - Navigate into the arduino-0022 directory and run the Arduino file by clicking on it. | ||
+ | - On the main menu of the Arduino IDE, select the menu item " | ||
+ | - Next, following the instructions on the Web page http:// | ||
+ | - Reboot and open the arduino application and checked the " | ||
+ | - Log in as the super user and add users to the dialout group in the /etc/group file. | ||
+ | - Reboot and then open the Arduino IDE. Select the " | ||
+ | \\ | ||
+ | **2. Write an Arduino application which reads character commands from the serial port and then performs the commands. If a command is to return data via the serial port, the application is to do so.**\\ | ||
+ | < | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | |||
+ | //Author: John T. Rine | ||
+ | |||
+ | |||
+ | int serialIn = 0; | ||
+ | int sensorValue = 0; | ||
+ | int digitalValue = 0; | ||
+ | int pin7 = 7; | ||
+ | int pin6 = 6; | ||
+ | int pin6State = LOW; | ||
+ | int pinState = LOW; | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | pinMode(pin7, | ||
+ | pinMode(pin6, | ||
+ | |||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | if (Serial.available() > 0) | ||
+ | { | ||
+ | serialIn = Serial.read(); | ||
+ | switch(serialIn) | ||
+ | { | ||
+ | case ' | ||
+ | sensorValue = analogRead(A0); | ||
+ | Serial.println(sensorValue, | ||
+ | serialIn = ' | ||
+ | break; | ||
+ | case ' | ||
+ | digitalValue = digitalRead(pin7); | ||
+ | Serial.println(digitalValue, | ||
+ | serialIn = ' | ||
+ | break; | ||
+ | case ' | ||
+ | if(pin6State == LOW) | ||
+ | { | ||
+ | pinState = HIGH; | ||
+ | pin6State = HIGH; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | pinState = LOW; | ||
+ | pin6State = LOW; | ||
+ | } | ||
+ | digitalWrite(pin6, | ||
+ | break; | ||
+ | |||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **3. If a Web server is not installed, Install the Apache 2 Web server software on the hardware which is to host the server.**\\ | ||
+ | After logging in as root, I performed an apt-get install of the apache 2 Web server packages.\\ | ||
+ | <cli> | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | apache2-mpm-worker apache2.2-common | ||
+ | Suggested packages: | ||
+ | apache2-suexec apache2-suexec-custom | ||
+ | The following NEW packages will be installed: | ||
+ | apache2 apache2-doc apache2-mpm-worker apache2-utils apache2.2-common | ||
+ | 0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded. | ||
+ | Need to get 2,779 kB of archives. | ||
+ | After this operation, 15.1 MB of additional disk space will be used. | ||
+ | Do you want to continue [Y/n]? y | ||
+ | Get:1 http:// | ||
+ | Get:2 http:// | ||
+ | Get:3 http:// | ||
+ | Get:4 http:// | ||
+ | Get:5 http:// | ||
+ | Fetched 2,779 kB in 7s (387 kB/s) | ||
+ | Selecting previously deselected package apache2-utils. | ||
+ | (Reading database ... 124913 files and directories currently installed.) | ||
+ | Unpacking apache2-utils (from .../ | ||
+ | Selecting previously deselected package apache2.2-common. | ||
+ | Unpacking apache2.2-common (from .../ | ||
+ | Selecting previously deselected package apache2-mpm-worker. | ||
+ | Unpacking apache2-mpm-worker (from .../ | ||
+ | Selecting previously deselected package apache2. | ||
+ | Unpacking apache2 (from .../ | ||
+ | Selecting previously deselected package apache2-doc. | ||
+ | Unpacking apache2-doc (from .../ | ||
+ | Processing triggers for man-db ... | ||
+ | Setting up apache2-utils (2.2.16-6+squeeze1) ... | ||
+ | Setting up apache2.2-common (2.2.16-6+squeeze1) ... | ||
+ | Enabling site default. | ||
+ | Enabling module alias. | ||
+ | Enabling module autoindex. | ||
+ | Enabling module dir. | ||
+ | Enabling module env. | ||
+ | Enabling module mime. | ||
+ | Enabling module negotiation. | ||
+ | Enabling module setenvif. | ||
+ | Enabling module status. | ||
+ | Enabling module auth_basic. | ||
+ | Enabling module deflate. | ||
+ | Enabling module authz_default. | ||
+ | Enabling module authz_user. | ||
+ | Enabling module authz_groupfile. | ||
+ | Enabling module authn_file. | ||
+ | Enabling module authz_host. | ||
+ | Enabling module reqtimeout. | ||
+ | Setting up apache2-mpm-worker (2.2.16-6+squeeze1) ... | ||
+ | Starting web server: apache2. | ||
+ | Setting up apache2 (2.2.16-6+squeeze1) ... | ||
+ | Setting up apache2-doc (2.2.16-6+squeeze1) ... | ||
+ | Reloading web server config: apache2. | ||
+ | root@dhcp-179:/ | ||
+ | root@dhcp-179:/ | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | libapache-ruby1.8 libreadline5 libruby1.8 | ||
+ | Suggested packages: | ||
+ | liberuby | ||
+ | The following NEW packages will be installed: | ||
+ | libapache-ruby1.8 libapache2-mod-ruby libreadline5 libruby1.8 | ||
+ | 0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. | ||
+ | Need to get 2,180 kB of archives. | ||
+ | After this operation, 8,147 kB of additional disk space will be used. | ||
+ | Do you want to continue [Y/n]? y | ||
+ | Get:1 http:// | ||
+ | Get:2 http:// | ||
+ | Get:3 http:// | ||
+ | Get:4 http:// | ||
+ | Fetched 2,180 kB in 5s (407 kB/s) | ||
+ | Selecting previously deselected package libreadline5. | ||
+ | (Reading database ... 126955 files and directories currently installed.) | ||
+ | Unpacking libreadline5 (from .../ | ||
+ | Selecting previously deselected package libruby1.8. | ||
+ | Unpacking libruby1.8 (from .../ | ||
+ | Selecting previously deselected package libapache-ruby1.8. | ||
+ | Unpacking libapache-ruby1.8 (from .../ | ||
+ | Selecting previously deselected package libapache2-mod-ruby. | ||
+ | Unpacking libapache2-mod-ruby (from .../ | ||
+ | Setting up libreadline5 (5.2-7) ... | ||
+ | Setting up libruby1.8 (1.8.7.302-2) ... | ||
+ | Setting up libapache-ruby1.8 (1.2.6-2) ... | ||
+ | Setting up libapache2-mod-ruby (1.2.6-2) ... | ||
+ | Enabling module ruby. | ||
+ | Run '/ | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | libapache2-reload-perl libbsd-resource-perl libdevel-symdump-perl | ||
+ | The following NEW packages will be installed: | ||
+ | libapache2-mod-perl2 libapache2-reload-perl libbsd-resource-perl libdevel-symdump-perl | ||
+ | 0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. | ||
+ | Need to get 1,146 kB of archives. | ||
+ | After this operation, 4,063 kB of additional disk space will be used. | ||
+ | Do you want to continue [Y/n]? y | ||
+ | Get:1 http:// | ||
+ | Get:2 http:// | ||
+ | Get:3 http:// | ||
+ | Get:4 http:// | ||
+ | Fetched 1,146 kB in 2s (418 kB/s) | ||
+ | Selecting previously deselected package libdevel-symdump-perl. | ||
+ | (Reading database ... 127688 files and directories currently installed.) | ||
+ | Unpacking libdevel-symdump-perl (from .../ | ||
+ | Selecting previously deselected package libapache2-mod-perl2. | ||
+ | Unpacking libapache2-mod-perl2 (from .../ | ||
+ | Selecting previously deselected package libapache2-reload-perl. | ||
+ | Unpacking libapache2-reload-perl (from .../ | ||
+ | Selecting previously deselected package libbsd-resource-perl. | ||
+ | Unpacking libbsd-resource-perl (from .../ | ||
+ | Processing triggers for man-db ... | ||
+ | Setting up libdevel-symdump-perl (2.08-3) ... | ||
+ | Setting up libapache2-mod-perl2 (2.0.4-7) ... | ||
+ | Enabling module perl. | ||
+ | Run '/ | ||
+ | Setting up libapache2-reload-perl (0.10-2) ... | ||
+ | Setting up libbsd-resource-perl (1.2904-1) ... | ||
+ | root@dhcp-179:/ | ||
+ | root@dhcp-179:/ | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | Suggested packages: | ||
+ | libapache2-mod-python-doc | ||
+ | The following NEW packages will be installed: | ||
+ | libapache2-mod-python | ||
+ | 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. | ||
+ | Need to get 122 kB of archives. | ||
+ | After this operation, 537 kB of additional disk space will be used. | ||
+ | Get:1 http:// | ||
+ | Fetched 122 kB in 0s (240 kB/s) | ||
+ | Selecting previously deselected package libapache2-mod-python. | ||
+ | (Reading database ... 128129 files and directories currently installed.) | ||
+ | Unpacking libapache2-mod-python (from .../ | ||
+ | Setting up libapache2-mod-python (3.3.1-9+b1) ... | ||
+ | Reloading web server config: apache2. | ||
+ | Processing triggers for python-central ... | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | libmysqlclient16 mysql-common | ||
+ | Suggested packages: | ||
+ | python-egenix-mxdatetime mysql-server-5.1 mysql-server python-mysqldb-dbg | ||
+ | The following NEW packages will be installed: | ||
+ | libmysqlclient16 mysql-common python-mysqldb | ||
+ | 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. | ||
+ | Need to get 2,101 kB of archives. | ||
+ | After this operation, 4,788 kB of additional disk space will be used. | ||
+ | Do you want to continue [Y/n]? y | ||
+ | Get:1 http:// | ||
+ | Get:2 http:// | ||
+ | Get:3 http:// | ||
+ | Fetched 2,101 kB in 5s (374 kB/s) | ||
+ | Selecting previously deselected package mysql-common. | ||
+ | (Reading database ... 128154 files and directories currently installed.) | ||
+ | Unpacking mysql-common (from .../ | ||
+ | Selecting previously deselected package libmysqlclient16. | ||
+ | Unpacking libmysqlclient16 (from .../ | ||
+ | Selecting previously deselected package python-mysqldb. | ||
+ | Unpacking python-mysqldb (from .../ | ||
+ | Setting up mysql-common (5.1.49-3) ... | ||
+ | Setting up libmysqlclient16 (5.1.49-3) ... | ||
+ | Setting up python-mysqldb (1.2.2-10+b1) ... | ||
+ | Processing triggers for python-support ... | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | apache2-mpm-prefork libonig2 libqdbm14 php5-cli php5-common php5-suhosin | ||
+ | Suggested packages: | ||
+ | php5-dev | ||
+ | The following packages will be REMOVED: | ||
+ | apache2-mpm-worker | ||
+ | The following NEW packages will be installed: | ||
+ | apache2-mpm-prefork libapache2-mod-php5 libonig2 libqdbm14 php-pear php5 php5-cli | ||
+ | php5-common php5-suhosin php5-xcache | ||
+ | 0 upgraded, 10 newly installed, 1 to remove and 0 not upgraded. | ||
+ | Need to get 7,101 kB of archives. | ||
+ | After this operation, 20.3 MB of additional disk space will be used. | ||
+ | Do you want to continue [Y/n]? y | ||
+ | Get:1 http:// | ||
+ | Get:2 http:// | ||
+ | Get:3 http:// | ||
+ | Get:4 http:// | ||
+ | Get:5 http:// | ||
+ | Get:6 http:// | ||
+ | Get:7 http:// | ||
+ | Get:8 http:// | ||
+ | Get:9 http:// | ||
+ | Get:10 http:// | ||
+ | Fetched 7,101 kB in 15s (445 kB/s) | ||
+ | dpkg: apache2-mpm-worker: | ||
+ | | ||
+ | Package apache2-mpm-worker is to be removed. | ||
+ | Package apache2-mpm-prefork is not installed. | ||
+ | Package apache2-mpm-event is not installed. | ||
+ | Package apache2-mpm-itk is not installed. | ||
+ | (Reading database ... 128207 files and directories currently installed.) | ||
+ | Removing apache2-mpm-worker ... | ||
+ | Stopping web server: apache2 ... waiting . | ||
+ | Selecting previously deselected package apache2-mpm-prefork. | ||
+ | (Reading database ... 128203 files and directories currently installed.) | ||
+ | Unpacking apache2-mpm-prefork (from .../ | ||
+ | Setting up apache2-mpm-prefork (2.2.16-6+squeeze1) ... | ||
+ | Starting web server: apache2. | ||
+ | Selecting previously deselected package libonig2. | ||
+ | (Reading database ... 128208 files and directories currently installed.) | ||
+ | Unpacking libonig2 (from .../ | ||
+ | Selecting previously deselected package libqdbm14. | ||
+ | Unpacking libqdbm14 (from .../ | ||
+ | Selecting previously deselected package php5-common. | ||
+ | Unpacking php5-common (from .../ | ||
+ | Selecting previously deselected package libapache2-mod-php5. | ||
+ | Unpacking libapache2-mod-php5 (from .../ | ||
+ | Selecting previously deselected package php5-cli. | ||
+ | Unpacking php5-cli (from .../ | ||
+ | Selecting previously deselected package php-pear. | ||
+ | Unpacking php-pear (from .../ | ||
+ | Selecting previously deselected package php5. | ||
+ | Unpacking php5 (from .../ | ||
+ | Selecting previously deselected package php5-suhosin. | ||
+ | Unpacking php5-suhosin (from .../ | ||
+ | Selecting previously deselected package php5-xcache. | ||
+ | Unpacking php5-xcache (from .../ | ||
+ | Processing triggers for man-db ... | ||
+ | Setting up libonig2 (5.9.1-1) ... | ||
+ | Setting up libqdbm14 (1.8.77-4) ... | ||
+ | Setting up php5-common (5.3.3-7+squeeze1) ... | ||
+ | Setting up libapache2-mod-php5 (5.3.3-7+squeeze1) ... | ||
+ | |||
+ | Creating config file / | ||
+ | Reloading web server config: apache2. | ||
+ | Setting up php5-cli (5.3.3-7+squeeze1) ... | ||
+ | |||
+ | Creating config file / | ||
+ | update-alternatives: | ||
+ | Setting up php-pear (5.3.3-7+squeeze1) ... | ||
+ | Setting up php5 (5.3.3-7+squeeze1) ... | ||
+ | Setting up php5-suhosin (0.9.32.1-1) ... | ||
+ | Setting up php5-xcache (1.3.0-7) ... | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | php5-suhosin is already the newest version. | ||
+ | php5-suhosin set to manually installed. | ||
+ | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. | ||
+ | root@dhcp-179:/ | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following NEW packages will be installed: | ||
+ | php5-mysql | ||
+ | 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. | ||
+ | Need to get 66.8 kB of archives. | ||
+ | After this operation, 250 kB of additional disk space will be used. | ||
+ | Get:1 http:// | ||
+ | Fetched 66.8 kB in 2s (27.0 kB/s) | ||
+ | Selecting previously deselected package php5-mysql. | ||
+ | (Reading database ... 128521 files and directories currently installed.) | ||
+ | Unpacking php5-mysql (from .../ | ||
+ | Processing triggers for libapache2-mod-php5 ... | ||
+ | Reloading web server config: apache2. | ||
+ | Setting up php5-mysql (5.3.3-7+squeeze1) ... | ||
+ | root@dhcp-179:/ | ||
+ | root@dhcp-179:/ | ||
+ | root@dhcp-179:/# | ||
+ | root@dhcp-179:/ | ||
+ | apache2.conf | ||
+ | conf.d | ||
+ | root@dhcp-179:/ | ||
+ | root@dhcp-179:/ | ||
+ | index.html | ||
+ | </ | ||
+ | \\ | ||
+ | **4. Write a CGI application or a PHP script which will give commands to the Arduino based upon commands handed to it from the Web and return data as required.**\\ | ||
+ | I found the following Linux C Arduino serial code at: http:// | ||
+ | < | ||
+ | /* | ||
+ | * Arduino-serial | ||
+ | * -------------- | ||
+ | | ||
+ | * A simple command-line example program showing how a computer can | ||
+ | * communicate with an Arduino board. Works on any POSIX system (Mac/ | ||
+ | * | ||
+ | * | ||
+ | * Compile with something like: | ||
+ | * gcc -o arduino-serial arduino-serial.c | ||
+ | * | ||
+ | * Created 5 December 2006 | ||
+ | * Copyleft (c) 2006, Tod E. Kurt, tod@todbot.com | ||
+ | * http:// | ||
+ | * | ||
+ | | ||
+ | * Updated 8 December 2006: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | * | ||
+ | * Updated 26 December 2007: | ||
+ | | ||
+ | | ||
+ | * | ||
+ | * Update 31 August 2008: | ||
+ | | ||
+ | * | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | void usage(void); | ||
+ | int serialport_init(const char* serialport, int baud); | ||
+ | int serialport_writebyte(int fd, uint8_t b); | ||
+ | int serialport_write(int fd, const char* str); | ||
+ | int serialport_read_until(int fd, char* buf, char until); | ||
+ | |||
+ | void usage(void) { | ||
+ | printf(" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "Note: Order is important. Set ' | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | |||
+ | int main(int argc, char *argv[]) | ||
+ | { | ||
+ | int fd = 0; | ||
+ | char serialport[256]; | ||
+ | int baudrate = B9600; | ||
+ | char buf[256]; | ||
+ | int rc,n; | ||
+ | |||
+ | if (argc==1) { | ||
+ | usage(); | ||
+ | exit(EXIT_SUCCESS); | ||
+ | } | ||
+ | |||
+ | /* parse options */ | ||
+ | int option_index = 0, opt; | ||
+ | static struct option loptions[] = { | ||
+ | {" | ||
+ | {" | ||
+ | {" | ||
+ | {" | ||
+ | {" | ||
+ | {" | ||
+ | {" | ||
+ | }; | ||
+ | | ||
+ | while(1) { | ||
+ | opt = getopt_long (argc, argv, " | ||
+ | | ||
+ | if (opt==-1) break; | ||
+ | switch (opt) { | ||
+ | case ' | ||
+ | case ' | ||
+ | n = strtol(optarg, | ||
+ | usleep(n * 1000 ); // sleep milliseconds | ||
+ | break; | ||
+ | case ' | ||
+ | usage(); | ||
+ | break; | ||
+ | case ' | ||
+ | baudrate = strtol(optarg, | ||
+ | break; | ||
+ | case ' | ||
+ | strcpy(serialport, | ||
+ | fd = serialport_init(optarg, | ||
+ | if(fd==-1) return -1; | ||
+ | break; | ||
+ | case ' | ||
+ | n = strtol(optarg, | ||
+ | rc = serialport_writebyte(fd, | ||
+ | if(rc==-1) return -1; | ||
+ | break; | ||
+ | case ' | ||
+ | strcpy(buf, | ||
+ | rc = serialport_write(fd, | ||
+ | if(rc==-1) return -1; | ||
+ | break; | ||
+ | case ' | ||
+ | serialport_read_until(fd, | ||
+ | printf(" | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | exit(EXIT_SUCCESS); | ||
+ | } // end main | ||
+ | | ||
+ | int serialport_writebyte( int fd, uint8_t b) | ||
+ | { | ||
+ | int n = write(fd,& | ||
+ | if( n!=1) | ||
+ | return -1; | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | int serialport_write(int fd, const char* str) | ||
+ | { | ||
+ | int len = strlen(str); | ||
+ | int n = write(fd, str, len); | ||
+ | if( n!=len ) | ||
+ | return -1; | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | int serialport_read_until(int fd, char* buf, char until) | ||
+ | { | ||
+ | char b[1]; | ||
+ | int i=0; | ||
+ | do { | ||
+ | int n = read(fd, b, 1); // read a char at a time | ||
+ | if( n==-1) return -1; // couldn' | ||
+ | if( n==0 ) { | ||
+ | usleep( 10 * 1000 ); // wait 10 msec try again | ||
+ | continue; | ||
+ | } | ||
+ | buf[i] = b[0]; i++; | ||
+ | } while( b[0] != until ); | ||
+ | |||
+ | buf[i] = 0; // null terminate the string | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | // takes the string name of the serial port (e.g. "/ | ||
+ | // and a baud rate (bps) and connects to that port at that speed and 8N1. | ||
+ | // opens the port in fully raw mode so you can send binary data. | ||
+ | // returns valid fd, or -1 on error | ||
+ | int serialport_init(const char* serialport, int baud) | ||
+ | { | ||
+ | struct termios toptions; | ||
+ | int fd; | ||
+ | | ||
+ | // | ||
+ | // serialport, | ||
+ | |||
+ | fd = open(serialport, | ||
+ | if (fd == -1) { | ||
+ | perror(" | ||
+ | return -1; | ||
+ | } | ||
+ | | ||
+ | if (tcgetattr(fd, | ||
+ | perror(" | ||
+ | return -1; | ||
+ | } | ||
+ | speed_t brate = baud; // let you override switch below if needed | ||
+ | switch(baud) { | ||
+ | case 4800: | ||
+ | case 9600: | ||
+ | #ifdef B14400 | ||
+ | case 14400: | ||
+ | #endif | ||
+ | case 19200: | ||
+ | #ifdef B28800 | ||
+ | case 28800: | ||
+ | #endif | ||
+ | case 38400: | ||
+ | case 57600: | ||
+ | case 115200: brate=B115200; | ||
+ | } | ||
+ | cfsetispeed(& | ||
+ | cfsetospeed(& | ||
+ | |||
+ | // 8N1 | ||
+ | toptions.c_cflag &= ~PARENB; | ||
+ | toptions.c_cflag &= ~CSTOPB; | ||
+ | toptions.c_cflag &= ~CSIZE; | ||
+ | toptions.c_cflag |= CS8; | ||
+ | // no flow control | ||
+ | toptions.c_cflag &= ~CRTSCTS; | ||
+ | |||
+ | toptions.c_cflag |= CREAD | CLOCAL; | ||
+ | toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl | ||
+ | |||
+ | toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw | ||
+ | toptions.c_oflag &= ~OPOST; // make raw | ||
+ | |||
+ | // see: http:// | ||
+ | toptions.c_cc[VMIN] | ||
+ | toptions.c_cc[VTIME] = 20; | ||
+ | | ||
+ | if( tcsetattr(fd, | ||
+ | perror(" | ||
+ | return -1; | ||
+ | } | ||
+ | |||
+ | return fd; | ||
+ | } | ||
+ | </ | ||
+ | This code could be modified to get data from the Web via an environment variable for example, data = getenv(" | ||
+ | \\ | ||
+ | **5. Install the CGI application or the PHP script on the Web server.**\\ | ||
+ | - Place the application into the required Web server directory. If it is a CGI application place the file into the cgi-bin directory, for example the / | ||
+ | - If required, set the CGI file permissions. | ||
+ | - chown root.root ???.cgi | ||
+ | - chmod +s ???.cgi | ||
+ | ======References====== | ||
+ | * Arduino Home: http:// | ||
+ | * Arduino IDE installation on Linux: http:// | ||
+ | * Arduino software download page: http:// | ||
+ | * Linux 32-bit version of the Arduino IDE: http:// | ||
+ | * Arduino and Linux: http:// | ||
+ | * Linux C Code to talk to an Arduino: http:// | ||
+ | * Getting Started with CGI Programming in C: http:// |