Below is the basic code for the simple Arduino server setup and the HTML control page.
Arduino server code:
[code]//zoomkat 10-17-10
//routerbot code
//for use with IDE 0018
//open serial monitor to see what the arduino receives
// http://arduino.cc/en/uploads/Tutorial/String.zip for WString.h
#include <WString.h>
#include <Ethernet.h>
#include <Servo.h>
byte mac] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip] = { 192, 168, 1, 102 }; // ip in lan
byte gateway] = { 192, 168, 1, 1 }; // internet access via router
byte subnet] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port
String readString = String(100);
String servo1 = String(10);
String servo2 = String(10);
Servo myservo1; // create servo object to control a servo
Servo myservo2;
//////////////////////
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
myservo1.attach(7);
myservo2.attach(6);
Serial.println(“bot1”); // so I can keep track of what is loaded
}
void loop(){
// Create a client connection
Client 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.append©;
}
//if HTTP request has ended
if (c == ‘\n’) {
///////////////
Serial.println(readString);
//readString looks like “GET /?-1500-1500 HTTP/1.1”
if (readString.length() >0) {
Serial.println(readString);
servo1 = readString.substring(7, 11);
servo2 = readString.substring(12, 16);
Serial.println(servo1);
Serial.println(servo2);
int n1;
int n2;
n1 = atoi(servo1); //convert string to number
n2 = atoi(servo2);
myservo1.writeMicroseconds(n1);
myservo2.writeMicroseconds(n2);
//myservo.write(n);
readString="";
}
///////////////////
//now output HTML data header
client.println(“HTTP/1.1 204 Zoomkat”);
client.println();
client.println();
delay(1);
//stopping client
client.stop();
/////////////////////
//clearing string for next read
readString="";
}}}}}
[/code]
Control web page:
[code]
Zoomkat's Routerbot
Web Control Page
Zoomkat's Routerbot Control Page
Foward-Stop-Reverse
F-F|
S-F|
-Stop-|
S-R|
F-R|
Turn-L-Stop-Turn-R
F-L|
S-L|
-Stop-|
S-R|
F-R|