外部 Web サーバーに PHP スクリプトがあります。ブラウザで表示www.example.com/test/myphp.php
すると、サーバーはスクリプトを正常に実行します。ここで、ブラウザで表示するときではなく、Arduino がそう言ったときにサーバーがスクリプトを実行するようにします。Arduino がスクリプトをリモートでトリガーして実行するようにします。
私はサーバー/php/Webの完全な初心者なので、特にGET synatxを使用する場合のヒントをいただければ幸いです(それが正しいコマンドである場合でも?)。Arduinoにはイーサネットシールドがあり、サーバーに正常に接続できます。以下のコードは正しく接続しますが、ブラウザで開いたときとは異なりwww.example.com/test/myphp.php
、Arduino からアクセスしたときに PHP ファイルは実際には実行されません :(
私のArduinoが指示したときにPHPファイルを実行するようにこれを変更する方法について何か提案はありますか?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.example.com";
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("SERIAL: Failed to configure Ethernet using DHCP");
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("SERIAL: connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
client.print("GET /test/myphp.php");
client.println(" HTTP/1.1");
client.println("Host: www.example.com");
client.println("User-Agent: Arduino");
client.println("Accept: text/html");
client.println("Connection: close");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("SERIAL: connection failed");
}
}
void loop()
{
// if there are incoming bytes available, print them
if (client.available()) {
char c = client.read();
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);
}
}