MIT App Inventor和Arduino以太网LED错误1109 URL无效

时间:2014-09-21 07:02:35

标签: android arduino ethernet

我开始使用带有以太网的arduino和带有我用MIT App发明人编写的软件的手机的家庭自动化系统的基础。我一直在玩教程中的代码,并使用浏览器和导航网址192.168.1.10/$1

让我的LED在本地计算机上使用互联网打开和关闭。
/*  thrown together by Randy Sarafan

 Allows you to turn on and off an LED by entering different urls.

 To turn it on:
 http://192.168.1.10/$1

 To turn it off:
 http://192.168.1.10/$2

     Based almost entirely upon Web Server by Tom Igoe and David Mellis

     Edit history: 
     created 18 Dec 2009
     by David A. Mellis
     modified 4 Sep 2010
     by Tom Igoe

     */

    #include <SPI.h>
    #include <Ethernet.h>

    boolean incoming = 0;

    // Enter a MAC address and IP address for your controller below.
    // The IP address will be dependent on your local network:
    byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
    //IPAddress ip(191,168,1,15); //<<< ENTER YOUR IP ADDRESS HERE!!! i commented this out and did it on the router side

    // Initialize the Ethernet server library
    // with the IP address and port you want to use 
    // (port 80 is default for HTTP):
    EthernetServer server(80);

    void setup()
    {
      pinMode(8, OUTPUT);

      // start the Ethernet connection and the server:
      Ethernet.begin(mac);
      server.begin();
      Serial.begin(9600);
    }

    void loop()
    {
      // listen for incoming clients
      EthernetClient client = server.available();
      if (client) {
        // an http request ends with a blank line
        boolean currentLineIsBlank = true;
        while (client.connected()) {
          if (client.available()) {
            char c = client.read();
            // if you've gotten to the end of the line (received a newline
            // character) and the line is blank, the http request has ended,
            // so you can send a reply

            //reads URL string from $ to first blank space
            if(incoming && c == ' '){ 
              incoming = 0;
            }
            if(c == '$'){ 
              incoming = 1; 
            }

            //Checks for the URL string $1 or $2
            if(incoming == 1){
              Serial.println(c);

              if(c == '1'){
                Serial.println("ON");
                digitalWrite(8, HIGH);
              }
              if(c == '2'){
                Serial.println("OFF");
                digitalWrite(8, LOW);
              }

            }

            if (c == '\n') {
              // you're starting a new line
              currentLineIsBlank = true;
            } 
            else if (c != '\r') {
              // you've gotten a character on the current line
              currentLineIsBlank = false;
            }
          }
        }
        // give the web browser time to receive the data
        delay(1);
        // close the connection:
        client.stop();
      }
    }

我遇到的问题是移动端。我创建了一个应用MIT应用程序发明者的应用程序,应该切换IP,但是给了我:

  

错误1109:指定的URL无效:192.168.1.10/$1

我非常困惑。我知道这个URL是有效的,因为我之前已经连接过它。有没有办法覆盖它或以其他方式修复它?

这是MIT应用程序发明人AIA来源:{​​{3}}

2 个答案:

答案 0 :(得分:0)

您应该在代码本身中指定IP地址。并改变“Ethernet.begin(mac);”到“Ethernet.begin(mac,ip);”。

在尝试使用App Inventor之前,您还应该尝试在浏览器中打开网页以检查它是否有效。

答案 1 :(得分:-1)

在AppInventor错误&#34;错误1109:指定的URL无效:192.168.1.10/$1"你可能忘了把#&#34; http://&#34;在你的地址。 例如,如果要将地址保存在全局变量或tinyDB中,则应将http://192.168.1.10/ $ 1放入 这将是您连接LED的地址。