PHP POST Arduino Ethernet

Hallo Community,
es ist mal wieder Zeit meinen Arduino zu Fordern.
Ich will mir eine kleine Kühlautomatik basteln die mir dann gleichzeitig die Temperaturen Loggen soll.
Soweit sogut, nun habe ich vor mittels POST von dem Arduino an eine PHP Datei zu schicken was jedoch nicht so wirklich Funktionieren will.

Mein Code:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.test.dolphin-webhosting.de";    // name address for Google (using DNS)

// 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;
String data = "data=Ich komme vom Arduino";
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("POST /arduino/index.php HTTP/1.1");
    client.println("Host: dolphin-webhosting.de");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println("Connection: close");
    client.println("User-Agent: Arduino 1/0");
    client.print("Content-Length: ");
    client.println(data.length());
    client.println();
    client.print(data);
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and 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);
  }
}

Hoffe ihr könnt mir ein wenig auf die Sprünge Helfen

Was funktioniert nicht?

Fehlermeldungen?

Welche Hardware verwendest du?

Ich glaube, nach dem Header müssen 2x Newline, bevor der POST-Teil kommt. Und dann check doch mal, ob das ...println() aus dem Arduino für den Server auch das richtige ist ... CR+NL oder NL+CR oder nur CR oder nur NL (ASCII-Code 10, 12 oder 13)? Da gibts immer etwas Verwirrung ...

Ansonsten sieh' dir den Beispiel-Sketch "Web-Client" aus der IDE nochmal genauer an. Und wenns garnicht gehen will, "bohrst du das Brett an der dünnsten Stelle" und nimmst erstmal GET (Argumente an URL anhängen) - das funktioniert immer und im PHP-Script ist es eine winzige Änderung ($_POST zu $_GET) :slight_smile:

Ich habe das ganze mit GET getestet damit geht es ohne Probleme jedoch POST gibt keine Daten zurück.
Habe den Code auch mal Umgeschrieben:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "http://www.test.dolphin-webhosting.de";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(46, 4, 59, 21);

// 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;

String data = "data=Hallo, ich bin Arduino";
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("POST /test.php HTTP/1.1");
    client.println("Host: test.dolphin-webhosting.de");
    client.print("Content-Length: ");
    client.println(data.length());
    client.println("Connection: close");
    client.println();
     client.println();
    client.print(data);
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and 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);
  }
}

dort habe ich wie schon gesagt wurde mal 2 Println eingefügt