Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使视频链接出现在Arduino w/Ethernet Shield上的HTML代码中?_Html_Arduino - Fatal编程技术网

如何使视频链接出现在Arduino w/Ethernet Shield上的HTML代码中?

如何使视频链接出现在Arduino w/Ethernet Shield上的HTML代码中?,html,arduino,Html,Arduino,我基本上是arduino代码的新手,下面的代码有问题。当我用arduino 0022编译它时,没有错误。如果我访问以太网屏蔽,我会看到HTML页面。问题在于我想在代码中发布的视频链接。我能看到画面,但链接永远不会出现。在这个框架中,我所看到的就是已经创建的HTML页面。代码或HTML格式是否有可能出错?是否有我需要使用的特定库?提前感谢您的帮助 #include <SPI.h> #include <Client.h> #include <Ethernet.h>

我基本上是arduino代码的新手,下面的代码有问题。当我用arduino 0022编译它时,没有错误。如果我访问以太网屏蔽,我会看到HTML页面。问题在于我想在代码中发布的视频链接。我能看到画面,但链接永远不会出现。在这个框架中,我所看到的就是已经创建的HTML页面。代码或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);
    }
  } 
}
#包括
#包括
#包括
#包括
#包括
#包括
字符链接[]=”http://www.anywebsite.com"; //视频链接
伺服倾斜;
伺服盘;
int panpos=90;
int-tiltpos=90;
字节mac[]={0xAA,0xBB,0xCC,0xDD,0xEE,0xFF}//物理mac地址
字节ip[]={192,128,13,169};//局域网中的ip
字节网关[]={192,128,13,1};//通过路由器访问互联网
字节子网[]={255,255,255,0}//子网掩码
服务器(80)//服务器端口
String readString=String(30)//用于从地址获取数据的字符串
无效设置(){
以太网开始(mac、ip、网关、子网);
Serial.begin(9600);
倾斜。连接(3);
附件(9);
倾斜写入(90);
泛写(90);
}
void循环(){
//创建客户端连接
Client=server.available();
如果(客户){
while(client.connected()){
if(client.available()){
char c=client.read();
//逐字符读取HTTP请求
if(readString.length()<100)
{
//将字符存储为字符串
readString+=c;
}
连续打印(c);
如果(c=='\n'){
if(readString.indexOf(“?”)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)
{
中心();
}
}
//现在,从标准标题开始输出HTML数据
client.println(“HTTP/1.1200ok”);
client.println(“内容类型:text/html”);
client.println();
//将背景设置为绿色
客户。打印(“”);
client.println(“
”); 客户。println(“”); client.println(“摄像机控制”); 客户。println(“”); client.println(“
”); client.println(“
”); 客户。println(“”); client.println(“
”); 客户。println(“”); 客户。println(“”); 客户。println(“”); 客户。println(“”); //正在清除下一次读取的字符串 readString=“”; //停止客户端 client.stop(); } } } } } void movetiltupstep(){ tiltpos=tilt.read(); Serial.println(tiltpos); 如果(倾斜位置>=66) { 倾斜写入(倾斜位置-2); } } void movetiltdownstep(){ tiltpos=tilt.read(); Serial.println(tiltpos); 如果(倾斜位置=4) { pan.write(panpos-4); } } void movepanrightstep(){ panpos=pan.read(); 序列号println(panpos); 如果(panpos=90;i--){ 泛写(i); } } 如果(倾斜位置<90) { 用于(int i=倾斜位置;i 90) { 对于(int i=tiltpos;i>=90;i--){ 倾斜。写入(i); } } }
是的,实际上,您的代码无法工作。让我们指出错误的行格式(“Link[]”连接到“frameborder”),这是一个应该以它开头的页面,幸运的是,在一个非常特殊的情况下,不需要使用内容长度标题等等,让我们关注一下您尝试做的事情

您尝试执行所谓的变量插值:假设字符串中的变量名“Link[]”将被另一个字符串替换。它是C或C++中不存在的。

有几种方法可以满足您的需要(您可以查看自Arduino-019以来存在的String类以及所谓的连接)

在您的情况下,您可以简单地这样做(未经测试,但应解释技巧):

client.print(“”);

它不如你想做的那么漂亮,但它足以满足你的需要。

我的工作就像一个魔咒。我做的唯一一件事是在我写的两行上改为:client.println。。。谢谢你的帮助,文森特!在你的情况下,它仍然有效。使用println()代替print()将强制在每个“print”之间添加新行,而不是连接字符。如果HTML的标准足够灵活,那么HTML“源代码”看起来就有点奇怪了。
client.print("<iframe width=640 height=360 src=");
client.print(Link); // Link is not between quotes!
client.println(" frameborder=0 allowfullscreen></iframe>");