我会建议使用来自Arduino的HTTP GET请求。根据您的堆栈代码,如果未设置DNS,它可能无法解析域名。所以我会建议使用IP,除非您知道它可以将您的域名解析为正确的IP。你可以看到更多的WebClient的例子:http://www.arduino.cc/en/Tutorial/WebClient
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /arduino.php?led=1 HTTP/1.1");
client.println("Host: www.yourwebsite.com");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
} 在循环
然后,你看看正确的响应(假设LEDPIN已设置定义):然后
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
if(c == 1){
digitalWrite(LEDPIN, HIGH);
} else {
digitalWrite(LEDPIN, LOW);
}
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
的PHP可以做是这样的:
if(isset($_GET['led']) && $_GET['led']){
// LED is on, send 0 to turn it off
echo "0";
} else {
// Turn LED on
echo "1";
}
?>
所以页面始终显示为0,除非你传递一个led传递和条件都得到满足。
如果您需要更多信息或更清晰的回复,请更新您的问题并提供更多详细信息。发布您的代码。