【发布时间】:2014-09-21 07:02:35
【问题描述】:
我正在使用带有以太网的 arduino 和带有我与 MIT App 发明者编程的软件的电话开始构建家庭自动化系统的基础。我一直在玩教程中的代码,并通过使用浏览器并导航 url 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();
}
}
我遇到的问题是在移动端。我用麻省理工学院应用程序发明者创建了一个应用程序,它应该切换 IP,而是给了我:
错误 1109:指定的 URL 无效:192.168.1.10/$1
我很困惑。我知道这个 URL 是有效的,因为我以前连接过它。有没有办法覆盖它或以其他方式修复它?
这是 MIT 应用程序发明者 AIA 来源:http://www.filedropper.com/internetled
【问题讨论】: