PaulS:
Go study client/server architecture, until you can see that two clients can NOT communicate directly.Then, when you do know how client/server architecture works, get the Arduino back out IF it can do anything like you want.
After I'd go to study, I think my project doesn't works well because Arduino is not possible as client. Finally, I use arduino web server to control my servo. But I've some problems, when I click button to control one servo, it doesn't stop when it's move. Here's my sketch:
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
Servo altitude; // create servo object to control a servo1
Servo azimuth; // create servo object to control a servo2
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xEC }; //physical mac address
byte ip[] = { 192, 168, 0, 3 }; // 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;
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
altitude.write(180); //set initial servo1 position if desired
azimuth.write(180); //set initial servo2 position if desired
altitude.attach(9); //the pin for the servo1 control
azimuth.attach(8); //the pin for the servo2 control
//enable serial data print
Serial.begin(9600);
Serial.println("server servo/pin 9,8 test 1.0"); // so I can keep track of what is loaded
}
void loop()
{
// 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 HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.print("<html><head>");
client.print("<title>Halaman Kontrol</title>");
client.println("</head>");
client.print("<body bgcolor='#3399FF'>");
client.println("<center><p><h1>Sistem Kendali Teleskop </h1></p><center><hr>
");
client.println("<form method=get name=form>");
client.println("<button name=b value=1 type=submit style=height:80px;width:150px><a href=\"/?altitude\"\">ALTITUDE</a></button>");
client.println("<button name=b value=1 type=submit style=height:80px;width:150px><a href=\"/?alt_stop\"\">STOP</a></button>");
client.println("
");
client.println("<button name=b value=1 type=submit style=height:80px;width:150px><a href=\"/?azimuth\"\">AZIMUTH</a></button>");
client.println("<button name=b value=1 type=submit style=height:80px;width:150px><a href=\"/?zm\"\">STOP</a></button>");
client.println("</form>
");
client.println("</html></body>");
delay(100);
//stopping client
client.stop();
if(readString.indexOf("altitude") >0){
for (int i = 0 ; i <=180; i=i+10){
altitude.write(i);
delay (1000);
}
}
if(readString.indexOf("alt_stop") >0){
altitude.write(0);
delay (1000);
}
if(readString.indexOf("azimuth") >0){
for (int i = 0 ; i <=180; i=i+10){
azimuth.write(i);
delay (1000);
}
if(readString.indexOf("azm_stop") >0){
azimuth.write(0);
delay (1000);
}
}
readString="";
}
}
}
}
}
The second question is, I want to insert html code from webcam software, named "webcam xp". It is for streaming.
Can I insert this code in one table on arduino web server?
<th scope="col"><script type="text/javascript">
var height_array = new Array();
var width_array = new Array();
width_array[1] = 640;
height_array[1] = 480;
</script>
<img src="http://DESSY-PC:8080/loading.jpg" class="webcam" id="webcam1" onmousedown="PTZMouseDown1(event)" width="640" height="480" alt="Live Stream" />
<script type="text/javascript">
<!--
currentCamera1= 1;
errorimg1= 0;
document.images.webcam1.onload = DoIt1;
document.images.webcam1.onerror = ErrorImage1;
function LoadImage1()
{
uniq1 = Math.random();
document.images.webcam1.src = "http://DESSY-PC:8080/cam_" + currentCamera1 + ".jpg?uniq="+uniq1;
document.images.webcam1.onload = DoIt1;
}
function PTZMouseDown1(e)
{
var IE = document.all?true:false;
var x,y;
var myx,myy;
var myifr = document.getElementById("_iframe-ptz");
tp = getElPos1();
myx = tp[0];
myy = tp[1];
if(IE){
var scrollX = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
var scrollY = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
x = event.clientX - myx + scrollX;
y = event.clientY - myy + scrollY;
} else {
x = e.pageX - myx;
y = e.pageY - myy;
}
if ((width_array[currentCamera1] != null) && (width_array[currentCamera1] > 0)) x = Math.round((x * 400) / width_array[currentCamera1]);
if ((height_array[currentCamera1] != null) && (height_array[currentCamera1] > 0)) y = Math.round((y * 300) / height_array[currentCamera1]);
if (x > 400) x = 400;
if (y > 300) y = 300;
if (myifr != null) myifr.src = "http://DESSY-PC:8080/ptz?src=" + currentCamera1 + "&moveto_x=" + x + "&moveto_y=" + y +"";
return true;
}
function getElPos1()
{
el = document.images.webcam1;
x = el.offsetLeft;
y = el.offsetTop;
elp = el.offsetParent;
while(elp!=null)
{ x+=elp.offsetLeft;
y+=elp.offsetTop;
elp=elp.offsetParent;
}
return new Array(x,y);
}
function ErrorImage1()
{
errorimg1++;
if (errorimg1>3){
document.images.webcam1.onload = "";
document.images.webcam1.onerror = "";
document.images.webcam1.src = "offline.jpg";
}else{
uniq1 = Math.random();
document.images.webcam1.src = "http://DESSY-PC:8080/cam_" + currentCamera1 + ".jpg?uniq="+uniq1;
}
}
function DoIt1()
{
errorimg1=0;
window.setTimeout("LoadImage1();", 40);
}
//-->
</script>
</th>