I added your code to my esp code.
String h = String(dht.readHumidity());
String t = String(dht.readTemperature());
String postStr = "humi=" + h + "&temp=" + t;
client.print(String("POST ") + "/esp/dht.php HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Connection: keep-alive\r\n" +
"Content-Length: " + postStr.length() + "\r\n\r\n" + postStr);
I had to make a string of h and t.
And I placed php file in xampp>htdocs>esp>dht.php, is it right?
My dht.php code:
<?php
require_once "connect.php";
if (isset($_POST['temp']))
{
$polaczenie = @new mysqli($host,$db_user,$db_password,$db_name);
if($polaczenie->connect_errno!=0)
{
echo "Error:".$polaczenie->connect_errno;
}
else
{
$date1 = date("y-m-d");
$temp = $_POST['temp'];
$humi = $_POST['humi'];
$polaczenie->query("insert into dht values (NULL,'$date1','$temp','$humi'");
$polaczenie->close();
}
}
?>
connect.php have the db_name, db_password etc.
But it still doesn't work. What may I do wrong?
Should esp be in servermode or client?