Hi everyone,
I have been working on a project for a wifi controlled robot with live wireless video feed, and have had it working great both within my LAN, and from a remote location. I used an example webserver code I downloaded as a starting point, and modified it to control the motors instead of simply switching an LED.
The way it is currently set up, I need two browser windows open - one for the control UI, and the other for the video feed. This works fine, but is a little cumbersome. So I decided to try to combine both into one webpage on an external server, using HTML's
Thanks for your help, hopefully I explained that clearly enough! Let me know if you have any questions.
Chris
I should add that I am using an Arduino UNO board, the Arduino WiFi shield, and the Arduino Motor Shield.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>"Centipede"</title>
</head><body>
<iframe src="http://192.168.1.71:8090" name="vid" height="425" width="800"> </iframe>
<iframe src="http://192.168.1.84:8089" name="ctrl" height="425" width="100"> </iframe>
</body></html>
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "CGD"; // your network SSID (name)
char pass[] = "-----"; // your network password
WiFiServer server(8082);
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT); // Direction for Motor1
pinMode(3, OUTPUT); // Speed for Motor1
pinMode(6, OUTPUT); // Direction for Motor2
pinMode(5, OUTPUT); // Speed for Motor2
WiFi.begin(ssid, pass);
server.begin();
}
void loop()
{
WiFiClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
String buffer = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c);
buffer+=c;
if (c == '\n' && currentLineIsBlank) {
//output the html code to generate the UI
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<font color='green'>Arduino Centipede</font>");
client.println("
");
client.print("<FORM action=\"http://192.168.1.84:8089/\" >");
//radio buttons for commands
client.print("<P> <INPUT type=\"radio\" name=\"status\" value=\"1\">Forward");
client.print("<P> <INPUT type=\"radio\" name=\"status\" value=\"2\">Reverse");
client.print("<P> <INPUT type=\"radio\" name=\"status\" value=\"3\">Left");
client.print("<P> <INPUT type=\"radio\" name=\"status\" value=\"4\">Right");
client.print("<P> <INPUT type=\"radio\" name=\"status\" value=\"0\">Stop");
////
client.print("<P> <INPUT type=\"submit\" value=\"Submit\"> </FORM>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
buffer="";
} else if (c == '\r') {
//Move forward
if(buffer.indexOf("GET /?status=1")>=0){
digitalWrite(2, HIGH); //motor direction (HIGH / LOW) (typical for all)
analogWrite(3, 255); //motor speed (values 0 thru 255) (typical for all)
digitalWrite(6, HIGH);
analogWrite(5, 255); }
// Move reverse
if(buffer.indexOf("GET /?status=2")>=0){
digitalWrite(2, LOW);
analogWrite(3, 255);
digitalWrite(6, LOW);
analogWrite(5, 255); }
// Turn left
if(buffer.indexOf("GET /?status=3")>=0){
digitalWrite(2, HIGH);
analogWrite(3, 150);
digitalWrite(6, LOW);
analogWrite(5, 150); }
// Turn Right
if(buffer.indexOf("GET /?status=4")>=0){
digitalWrite(2, LOW);
analogWrite(3, 150);
digitalWrite(6, HIGH);
analogWrite(5, 150); }
// Stop
if(buffer.indexOf("GET /?status=0")>=0){
digitalWrite(2, LOW);
analogWrite(3, 0);
digitalWrite(6, LOW);
analogWrite(5, 0); }
}
else {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}