To save people downloading it:
//Adam Henrichs 22/05/2012
#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Udp.h>
#include <Servo.h>
//Pin Assignments
const int upPin =5;
const int downPin =6;
const int leftPin =7;
const int rightPin =8;
//Ethernet Initialising
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 10, 0, 0, 9 }; // ip in lan
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString = String(30); //string for fetching data from address
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
pinMode(upPin, OUTPUT);
pinMode(downPin, OUTPUT);
pinMode(leftPin, OUTPUT);
pinMode(rightPin, OUTPUT);
}
void loop()
{
digitalWrite(upPin, LOW);
digitalWrite(downPin, LOW);
digitalWrite(leftPin, LOW);
digitalWrite(rightPin, LOW);
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100)
{
//store characters to string
readString += c;
}
Serial.print(c);
if (c == '\n') {
if (readString.indexOf("?") <0)
{
//do nothing
}
else
{
if(readString.indexOf("UP=UP") >0)
{
cameraup();
}
else if(readString.indexOf("DN=DN") >0)
{
cameradown();
}
else if(readString.indexOf("LT=LT") >0)
{
cameraleft();
}
else if(readString.indexOf("RT=RT") >0)
{
cameraright();
}
else if(readString.indexOf("ST=ST") >0)
{
camerastop();
}
}
// now output HTML data starting with standard header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//set background to green
client.print("<body style=background-color:green>");
client.println("<hr />");
client.println("<center>");
client.println("<h1>Camera control</h1>");
client.println("<form method=get name=SERVO>");
client.println("<input type=submit value=UP name=UP style=\"width:100px\">
");
client.println("<input type=submit value=LT name=LT style=\"width:100px\"><input type=submit value=ST name=ST style=\"width:100px\"><input type=submit value=RT name=RT style=\"width:100px\">
");
client.println("<input type=submit value=DN name=DN style=\"width:100px\">");
client.println("</form>");
client.println("</center>");
client.println("</body></html>");
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}
void movetiltupstep()
{
digitalWrite(upPin, HIGH);
}
void movetiltdownstep()
{
digitalWrite(downPin, HIGH);
}
void movepanleftstep()
{
digitalWrite(leftPin, HIGH);
}
void movepanrightstep()
{
digitalWrite(rightPin, HIGH);
}
void center()
{
digitalWrite(rightPin, LOW);
digitalWrite(leftPin, LOW);
digitalWrite(upPin, LOW);
digitalWrite(downPin, LOW);
}
}
Now:
String readString = String(30); //string for fetching data from address
That doesn’t create a 30-character string, it creates a string with “30” in it.
if (readString.length() < 100)
Just as well because you are reading up to 100 characters.
The String class tends to fragment memory. You are better off reading into a char array, and then doing “strstr” on it.
In it’s current iteration it has to be manually set back to low, but I’d rather it send “up” (and therefore HIGH) only while the button is held down.
I doubt if you can do that, without some fancy Java on the web page. The form is transmitted in one batch.