使用 Arduino 通过 PHP 脚本发送值

Send values through a PHP-script with Arduino

我正在尝试让我的 Arduino With Ethernet Shield 调用 PHP 脚本。域是这样的:sub.domain.com 而我要调用的脚本是这样的 script.php?value1=value&somevalue2=somevalue&value3=somevalue.

我试着让它与 Arduino 库附带的示例一起工作,但我没有成功。

EthernetClient ethClient;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };
char server[] = "sub.domain.com";

void setup() {
    [...]
    if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
    }

    [...]
}

void loop() {   
    [...] 
  if (ethClient.connect(server, 80)) {
    Serial.println("Conected to: " + String(server));
    String getUrl = "/script.php?location=" + String(LOCATIONID) + "&sc=2&feedP=" + String(feedBar) + "&returnP=" + String(returnBar) ;
    Serial.println(getUrl);
    // Make a HTTP request:
    ethClient.println("GET " + getUrl + " HTTP/1.1");
    ethClient.println("Host: sub.domain.com");
    ethClient.println("Connection: close");
    ethClient.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("Could not connect to: " + String(server));
  }

if (ethClient.available()) {
  char c = ethClient.read();
  Serial.println("Respons: ");
  Serial.print(c);
}
    [...]
}

不使用子域时有效。