我會建議使用來自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可以做是這樣的:
<?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
傳遞和條件都得到滿足。
如果您需要更多信息或更清晰的回覆,請更新您的問題並提供更多詳細信息。發佈您的代碼。
PHP文件看起來像這樣<?php echo 1; ?> –
歡迎來到SO。清楚的是,你有一個叫做PHP頁面的Arduino。根據PHP頁面的結果,您希望LED打開或關閉。你傳遞給PHP頁面的信息是什麼?什麼情況?另請發佈您的Arduino代碼和PHP代碼示例。 – Twisty