2012-03-06 5 views
0

私はarduinoコードの初心者ですが、次のコードに問題があります。私がarduino 0022でコンパイルするとき、エラーはありません。イーサネットシールドにアクセスすると、HTMLページが正常に表示されます。問題は、コードに投稿したいビデオへのリンクが付いてくる。私はフレームを見ることができますが、リンクが現れません。そのフレーム内には、作成されたHTMLページがすべて表示されます。コードやHTMLの書式に誤りがある可能性はありますか?私が使う必要がある特定の図書館はありますか?あらかじめ助けてくれてありがとう!Arduino/Ethernet ShieldのHTMLコード内にビデオリンクを作成するにはどうすればいいですか?

#include <SPI.h> 
#include <Client.h> 
#include <Ethernet.h> 
#include <Server.h> 
#include <Udp.h> 
#include <Servo.h> 
char Link[]= "http://www.anywebsite.com"; //video link 
Servo tilt; 
Servo pan; 
int panpos = 90; 
int tiltpos = 90; 
byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; //physical mac address 
byte ip[] = { 192, 128, 13, 169 };   // ip in lan 
byte gateway[] = { 192, 128, 13,1 };   // internet access via router 
byte subnet[] = { 255, 255, 255, 0 };     //subnet mask 
Server 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); 
tilt.attach(3); 
pan.attach(9); 
    tilt.write(90); 
    pan.write(90); 
} 
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 += c; 
     } 
     Serial.print(c); 
     if (c == '\n') { 
      if (readString.indexOf("?") <0) 
      { 
      //do nothing 
      } 
      else 
      {   
      if(readString.indexOf("UP=UP") >0) 
       { 
       movetiltupstep(); 
       } 
      else if(readString.indexOf("DN=DN") >0) 
       { 
       movetiltdownstep(); 
       } 
      else if(readString.indexOf("LT=LT") >0) 
       { 
       movepanleftstep(); 
       } 
      else if(readString.indexOf("RT=RT") >0) 
       { 
       movepanrightstep(); 
       } 
      else if(readString.indexOf("CN=CN") >0) 
      { 
      center(); 
      } 
     } 
     // 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:blue>"); 
     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\"><br>"); 
     client.println("<input type=submit value=LT name=LT style=\"width:100px\"><input type=submit value=CN name=CN style=\"width:100px\"><input type=submit value=RT name=RT style=\"width:100px\"><br>"); 
     client.println("<input type=submit value=DN name=DN style=\"width:100px\">"); 
     client.println("<hr />"); 
     client.println("<iframe width= 640 height= 360 src= Link[]frameborder= 0 allowfullscreen></iframe>"); 
     client.println("</form>"); 
     client.println("</center>"); 
     client.println("</body></html>"); 
     //clearing string for next read 
     readString=""; 
     //stopping client 
     client.stop(); 
     } 
     } 
    } 
    } 
} 
void movetiltupstep(){ 
    tiltpos = tilt.read(); 
    Serial.println(tiltpos); 
    if (tiltpos >= 66) 
    { 
    tilt.write(tiltpos - 2); 
    } 
} 
void movetiltdownstep(){ 
    tiltpos = tilt.read(); 
    Serial.println(tiltpos); 
    if (tiltpos <= 116) 
    { 
    tilt.write(tiltpos + 2); 
    } 
} 
void movepanleftstep(){ 
    panpos = pan.read(); 
    Serial.println(panpos); 
    if (panpos >= 4) 
    { 
    pan.write(panpos - 4); 
    } 
} 
void movepanrightstep(){ 
    panpos = pan.read(); 
    Serial.println(panpos); 
    if (panpos <= 176) 
    { 
    pan.write(panpos + 4); 
    } 
} 
void center(){ 
    panpos = pan.read(); 
    tiltpos = tilt.read(); 
    Serial.println(panpos); 
    if (panpos < 90) 
    { 
    for(int i = panpos; i <= 90; i++) { 
     pan.write(i); 
    } 
    } 
    else if (panpos > 90) 
    { 
    for(int i = panpos; i >= 90; i--) { 
     pan.write(i); 
} 
    } 
    if (tiltpos < 90) 
    { 
    for(int i = tiltpos; i <= 90; i++) { 
     tilt.write(i); 
    } 
    } 
    else if (tiltpos > 90) 
    { 
    for(int i = tiltpos; i >= 90; i--) { 
     tilt.write(i); 
    } 
    } 
} 

答えて

0

はい、実際は、コードは機能しません。間違った形式の行( "frameborder"に連結されている "Link []")、つまり< html>で始まるページを貼り付けてください。あなたはContent-Lengthヘッダーは必要ではないなど、あなたがしようとしたことに焦点を当てましょう。

変数補間と呼ばれることを試みました。文字列内の変数名 "Link []"が別の文字列に置き換えられると仮定しました。これはCやC++には存在しないものです。

Arduino-019以降に存在するStringクラスと、連結http://arduino.cc/en/Reference/StringConcatと呼ばれるものがあります。あなたのケースでは

、あなたは、単に(テストしていないが、トリックを説明しなければならない)ことを行うことができます。

client.print("<iframe width=640 height=360 src="); 
client.print(Link); // Link is not between quotes! 
client.println(" frameborder=0 allowfullscreen></iframe>"); 

それはあなたがやりたいことよりも少ない美しいですが、それはあなたが必要なもののために十分です。

+0

私は魅力的です。私がした唯一のことは、私が置いた2行のclient.printではなく、client.println ...助けてくれたVincent! –

+0

あなたの場合でもそれはまだ有効です。文字を連結する代わりに、print()の代わりにprintln()を使用すると、各 "print"の間に改行が追加されます。その場合、HTMLの標準は十分柔軟であり、HTMLの「ソースコード」はちょっと変わって見えます。 –

関連する問題