Hallo zusammen
Habe einen ESP8266 und ein Raspberry Pi und mochte mit Post Daten von ESP8266 zum Raspberry Pi (PHP) und wieder zurückschicken
Die Antwort von Raspberry PI ist:
wert1
wert2 ***0
Hallo du da!!!
Meine Frage ist jetzt: Warum wird hinter wert1 und wert2 nix angezeigt?
Ich habe erwarte:
wert1 --> Message from ESP8266
wert2 --> Wo kommt der Text her!!!
die 0 ist die Lange von wert2
Aber das ganze wird ja zum ESP8266 zurückgeschickt.
die Antwort von ESP8266:
200
<br>wert1 Message from ESP8266<br>wert2 Wo kommt der Text her!!!***24<br>Hallo du da!!!<br>
Jetzt meine 2 Frage warum wird beim ESP8266 für wert1 und wert2 was angezeigt? wo ja beim Raspberry nix angezeigt worden ist und die lange von wert2 0 ist
C
Esp82866
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
const char* ssid = "abc";
const char* password = "123";
void setup() {
Serial.begin(115200); //Serial connection
WiFi.begin(ssid, password); //WiFi connection
while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion
delay(500);
Serial.println("Waiting for connection");
}
Serial.println(WiFi.localIP());
}
void loop() {
if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status
HTTPClient http; //Declare object of class HTTPClient
//http.begin("http://192.168.178.22:1337/post"); //Specify request destination
http.begin("http://192.168.1.2/post.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //Specify content-type header
int httpCode = http.POST("text=Message from ESP8266&test=Wo kommt der Text her!!!"); //Send the request
String payload = http.getString(); //Get the response payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
}else{
Serial.println("Error in WiFi connection");
}
delay(30000); //Send a request every 30 seconds
}
PHP:
<?php
$wert1 = $_POST["text"];
echo("<br>wert1 ".$wert1);
$wert2 = $_POST["test"];
echo("<br>wert2 ".$wert2."***".strlen($wert2));
echo("<br>Hallo du da!!!<br>");
?>
Alles anzeigen