Hey guys,
I made a web controlled thermostat out of my arduino:
the server is at varano.eu.pn, check it out if you want, and the arduino runs a GET command on the server to find out what temperature I set.
I would also like the arduino to POST data to the server, for example the room temperature it already displays on its screen.
I have no idea where to start... can someone suggest me a path? What will my php say? what does the arduino do?
and the arduino runs a GET command on the server to find out what temperature I set.
So, you know how to use a GET command to trigger a php script. And, you know how to write a php script to respond to a GET command.
I would also like the arduino to POST data to the server
Why? The differences between a POST command and a GET command are rather trivial. If you already know how to GET a script to do something, why not go with that approach?
POST is usually used when trying to hide the data that the script needs from prying eyes. I fail to see how the temperature in your room is a secret bit of data, or why you care if a packet sniffer sees the temperature.
Last week I had done a small script to connect my arduino to Mysql with a GET method.
Here is my script:
<html>
<?php
$value = $_GET['value'];
//echo $value;
Â
//Get date and time
// Return date/time info of a timestamp; then format the output
$mydate=getdate(date("U"));
$timestamp = "$mydate[year]-$mydate[mon]-$mydate[mday] $mydate[hours]:$mydate[minutes]:$mydate[seconds]";
//-----------Setup Mysql Connection
Â
$user = 'energy';
$pass = 'monitor';
$hostname = 'localhost';
$databaseName = 'energymonitor';
Â
$linkSQL = mysqli_connect($hostname,$user,$pass,$databaseName);
Â
Â
if (mysqli_connect_errno())
 {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }
Â
//Construct the sql query and store it in a varaible
$sql="INSERT INTO sensores (name, value,date) VALUES('modem','$value','$timestamp')";
if (!mysqli_query($linkSQL,$sql))
{
die('Error: ' . mysqli_error($linkSQL));
}
Â
echo 'Success';
mysqli_close($linkSQL);
Â
?>
</html>
if (client.connect(serverName, 80)) {
   // Serial.println("connecting...");
   // send the HTTP PUT request:
   client.print("GET http://varano.eu.pn/arduino.php?t=");
   client.print(TEMPr);
   client.println(" HTTP/1.0");
   // client.println("Host: www.arduino.cc");
   // client.println("User-Agent: arduino-ethernet");
   // client.println("Connection: close");
   client.println();
  }
this is my server's code
<html>
<?php
 // ARDUINO TO WEB SERVER
 $t = $_GET['t'];
 file_put_contents('arduino-temp.txt', '<'.$t.'.0'.'>');
 //return 'ok';
?>
</html>
   client.print("GET http://varano.eu.pn/arduino.php?t=");
The Arduino only communicates using one protocol, so the http: bit is not necessary. The client.connect() call has already connected to the server, so the server name is not necessary.