Controlling Hardware Remotely via the Web (Arduino Uno/Ethernet Module)
John T. Rine
04/16/2012
======Objectives======
======Prerequisites======
- Knowledge of microprocessors
- Knowledge of the Arduino Wiring language
- Knowledge of C/C++
- Knowledge of basic networking
======Background======
======Scope======
======Attributes======
The course requirements for HPC Experience I projects are listed at:\\
http://lab46.corning-cc.edu/haas/hpc1/tasks
This project has the following project attributes described on that page:
======Project Attributes======
The following are the programming attributes you must consider while undertaking a project for credit in this course:
^ Attribute ^ Qty needed ^ Description ^
| maintenance | 4 |upkeep of an existing resource is undertaken |
| configuration | 4 |configuration of a (new) resource is achieved |
| logging | 4 |status of a resource is recorded |
| implementation | 4 |a new resource is implemented and brought on-line |
| enhancement | 4 |an existing resource is improved upon |
| virtualization | 4 |a resource is deployed within a virtualized environment |
| redundancy | 4 |a resource's availability or contents are hardened due to backups or avoiding a single point of failure |
| administration | 4 |a resource receives oversight maintenance to better direct its capabilities |
| exploration | 4 |exploration of new concepts/resources is undertaken |
| log analysis | 4 |collected log data is analyzed to accomplish some ends |
| troubleshooting | 4 |a problem is explored/solved using troubleshooting techniques |
| security | 4 |a resource is hardened due to security improvements |
There are a total of 48 items needed; with a maximum of 8 attributes achievable per project, that makes for a __minimum__ of 6 projects you must perform during the semester.
Note that where multiple quantities of attributes are concerned, only a single instance of an attribute can be achieved on any single project.
======Code======
===Arduino Web Server Example Code with my mac and IP addresses===
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
#include
#include
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xC5, 0x92 }; //The suggested mac address
IPAddress ip(192,168,1,3); //An open IP address on my home network
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
======Execution======
Today, April 16, 2012, I purchased an Arduino Uno and an Arduino Ethernet Shield at Radio Shack. When I got them home, I downloaded and installed the Arduino 1.0 IDE for Windows. Next, I assembled the Arduino Uno and the Ethernet shield. I plugged one end of the USB programming cable into the Arduino Uno and the other end into the computer on which I installed the Arduino 1.0 IDE. Installing the device driver is a little bit on a pain; after plugging the Arduino's USB cable into the computer used to develop sketches, let the driver install fail, then go to device manager, select the unknown device, select browse the computer for the device driver. On this pop-up, enter the path to the Arduino driver library (and not the FTDI folder-this is an Uno and does not use the FTDI chip) and let it find the driver. After successfully installing the driver for the Arduino Uno, I opened one of the example sketches, File->Examples->Basics->Blink. Next, I complied this 'sketch',
sketch->verify/compile. Lastely, I uploaded the compiled sketch to the Arduino, file->upload. The Arduino's yellow led blinked once per second, success!
Next, I found an Ethernet example, file->examples->Ethernet->Web server, and opend it in the Arduino IDE. I changed the mach address to the address listed on the sticker on the front of the Ethernet shield's container. I also changed the IP address tio an open address on my home network-192.168.1.3. I complied the sketch and uploaded it to the Arduino. I plugged one end
of a spare Ethernet cable into the router; I plugged the other end of the cable into Ethernet shield. Lastly, I plugged a power supply (wall wart) into the Arduino's power connector. The LEDs on the Arduino and Ethernet shield came on. I pointed my broswer to the Arduino's IP address. The Web server returned values of 6 of the Arduino's analog inputs, Cool! see an image of the Web page below.\\
\\
{{:user:jr018429:portfolio:arduino_web_server_1.jpg?200|}}\\
\\
I haven't yet forwarded a port to the Arduino Web server to expose it to the outside world; right now, it is only accessible from inside my network.\\
After getting the Arduino Web server to work, I added it as a new project to my portfolio. I plan to add hardware control and improve the server. The Ethernet shield also has a connector for an SD card on which data can be stored.
======Reflection======
======References======
* http://arduino.cc/en/Main/arduinoBoardUno
* http://arduino.cc/en/Main/ArduinoEthernetShield
* http://arduino.cc/en/Guide/ArduinoEthernetShield
* http://arduino.cc/en/Reference/Ethernet
* http://www.wiznet.co.kr/UpLoad_Files/ReferenceFiles/W5100_Datasheet_v1.2.2.pdf
* http://arduino.cc/en/Reference/SD