【问题标题】:Connecting Arduino with Ip Camera将 Arduino 与网络摄像机连接
【发布时间】:2016-04-28 03:46:37
【问题描述】:
/*


 Arduino with Ethernet Shield
 */

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h> 
int led = 4;
Servo microservo; 
int pos = 0; 
byte mac[ ] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte ip[ ] = { 10, 0,1,6 };                      // ip in lan (that's what you need to use in your browser. ("10.0.1.2")
byte gateway[ ] = { 10,0, 1, 25 };                   // internet access via router
byte subnet[ ] = { 255, 255, 255, 0 };                  //subnet mask
EthernetServer server(80);                             //server port     
String readString;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  pinMode(led, OUTPUT);
  microservo.attach(7);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


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.println("<HTML>");
           client.println("<HEAD>");
           client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
           client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
           client.println("<link rel='stylesheet' type='text/css' href='http://10.0.1.2/top.htm' />");
           client.println("<TITLE>Arduino Home Security System</TITLE>");
           client.println("</HEAD>");
           client.println("<BODY>");
           client.println("<H1>Abel & Herwandi</H1>");
           client.println("<hr />");
           client.println("<br />");  
           client.println("<H2>Arduino with Ethernet Shield</H2>");
           client.println("<br />");  
           client.println("<a href=\"/?button1on\"\">Turn On LED</a>");
           client.println("<a href=\"/?button1off\"\">Turn Off LED</a><br />");   
           client.println("<br />");     
           client.println("<br />"); 
           client.println("<a href=\"/?button2on\"\">Rotate Left</a>");
           client.println("<a href=\"/?button2off\"\">Rotate Right</a><br />"); 
           client.println("<p>Designed by Abel & Herwandi. SCUT Class 5</p>");  
           client.println("<br />"); 
           client.println("</BODY>");
           client.println("</HTML>");

           delay(1);
           //stopping client
           client.stop();
           //controls the Arduino if you press the buttons
           if (readString.indexOf("?button1on") >0){
               digitalWrite(led, HIGH);

           }
           if (readString.indexOf("?button1off") >0){
               digitalWrite(led, LOW);
           }
           if (readString.indexOf("?button2on") >0){
                for(pos = 0; pos < 180; pos += 3)  // goes from 0 degrees to 180 degrees 
                {                                  // in steps of 1 degree 
                  microservo.write(pos);              // tell servo to go to position in variable 'pos' 
                  delay(15);                       // waits 15ms for the servo to reach the position 
                } 
           }
           if (readString.indexOf("?button2off") >0){
                for(pos = 180; pos>=1; pos-=3)     // goes from 180 degrees to 0 degrees 
                {                                
                  microservo.write(pos);              // tell servo to go to position in variable 'pos' 
                  delay(15);                       // waits 15ms for the servo to reach the position 
                } 
           }
            //clearing string for next read
            readString="";  

         }
       }
    }
}
} 

我正在使用 Arduino uno 板、Arduino 以太网屏蔽和 dcs-930L Ip 摄像头和伺服电机开发安全系统,我的地址是直接从网络浏览器访问视频和照片,我使用以太网屏蔽设置一个网站,以便我可以控制它实际工作的伺服,所以我想做的是设置一个按钮,这样当点击它时,它会给我一个来自我的网络摄像机的视频/图像,它可以在同一个 Arduino 内网站或打开另一个窗口浏览器!我很感激任何帮助!谢谢

【问题讨论】:

  • 如果你想在同一个arduino页面中,你可以尝试添加一个指向相机地址的iframe;如果你想打开一个新的浏览器页面,只需谷歌搜索“javascript 打开新页面”,你会发现大量指南
  • @frarugi87 感谢您的帮助,但到目前为止仍然是新手,您可以通过指向相机地址的 iframe 进行指导吗?
  • 根据我的经验,获得帮助的最快方法是使用 google。如果你用谷歌搜索“iframe”,第一个结果就是 w3p 指南。最基本的例子是:&lt;iframe src="http://www.w3schools.com"&gt;&lt;/iframe&gt;。只需将 src 参数更改为您需要的页面即可。
  • 只说一句:不知道你能不能在浏览器中看到,。因为有时安全策略会阻止在 iframe 中显示其他域。我不确定“其他域”是否也是同一本地网络中的两个不同 IP,但如果是这种情况,解决方案可能会更复杂
  • 感谢您的帮助,但 iframe 似乎不是 arduino 参数或函数,所以很遗憾它不起作用

标签: arduino webserver arduino-uno ip-camera arduino-ide


【解决方案1】:

如果您想在网站上添加一个按钮以打开一个显示 IP 摄像机源的新窗口,您可以使用此 HTML,只需将 PutUrlHere 替换为摄像机源的 URL:

<a href="PutUrlHere" target="_blank">
    <input type="button" value="Show Camera">
</a>

编辑:

对于您的程序,您应该能够在希望按钮显示的任何位置执行此操作:

client.println("<a href='PutUrlHere' target='_blank'><input type='button' value='Show Camera'></a>");

【讨论】:

  • 非常感谢!我插入了代码,它就像一个魅力
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-10
  • 2016-09-23
  • 2012-12-20
  • 2013-02-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多