I made some changes to the sketch, to make insertion in one void, instead of 5... but that does not save too much memory... If the sketch leaves belloy 1000 bytes of memory, then problems appear. It is clear to me now, that it's a memory problem. If I will not managed to achieve my goal with PHP... then I will buy a MEGA. I have the whole weekend ahead.
I will not get mad if anyone cand help me with arduino code for the PHP thing...
Right not I have those 3 PHP files.
review_data.php - for displaying the data in a browser and this works and looks nice:
<?php
// Start MySQL Connection
include('dbconnect.php');
//
$selected = mysql_select_db($Database, $dbh);
?>
<html>
<head>
<title>Temperature and Humidity Sensors:</title>
<style type="text/css">
.table_titles, .table_cells_odd, .table_cells_even {
padding-right: 20px;
padding-left: 20px;
color: #000;
}
.table_titles {
color: #FFF;
background-color: #009ACD;
}
.table_cells_odd {
background-color: #CCC;
}
.table_cells_even {
background-color: #FAFAFA;
}
table {
border: 2px solid #333;
}
body { font-family: "Trebuchet MS", Arial; }
</style>
</head>
<body>
<h1>Temperatures and humidity data:</h1>
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="table_titles">ID</td>
<td class="table_titles">Date and Time</td>
<td class="table_titles">LOCATION</td>
<td class="table_titles">TEMPERATURE</td>
<td class="table_titles">HUMIDITY</td>
</tr>
<?php
// Retrieve all records and display them
$result = mysql_query("SELECT * FROM roomtemp ORDER BY DATETIME DESC");
// Used for row color toggle
$oddrow = true;
// process every record
while( $row = mysql_fetch_array($result) )
{
if ($oddrow)
{
$css_class=' class="table_cells_odd"';
}
else
{
$css_class=' class="table_cells_even"';
}
$oddrow = !$oddrow;
echo '<tr>';
echo ' <td'.$css_class.'>'.$row["ID"].'</td>';
echo ' <td'.$css_class.'>'.$row["DATETIME"].'</td>';
echo ' <td'.$css_class.'>'.$row["LOCATION"].'</td>';
echo ' <td'.$css_class.'>'.$row["TEMPERATURE"].'</td>';
echo ' <td'.$css_class.'>'.$row["HUMIDITY"].'</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>
then i have: dbconnect.php - where are the data connection for mysql server:
<?php
$Username = "arduino"; // enter your username for mysql
$Password = "myarduino"; // enter your password for mysql
$Hostname = "localhost"; // this is usually "localhost" unless your database resides on a different server
$Database = "arduino_roomtemp"; //database name
$dbh = mysql_connect($Hostname , $Username, $Password) or die (mysql_error());;
@mysql_select_db($Database) or die (mysql_error());
?>
and the most important part is: add_data.php, and of course the arduino code, and this is very unclear to me.
add_data.php looks like:
<?php
include("connect.php");
$link=Connection();
//$temp1=$_POST["temp1"];
//$hum1=$_POST["hum1"];
$query = "insert into roomtemp (LOCATION, TEMPERATURE, HUMIDITY) values ('ETAJ-DORMITOR', '".$_GET["memoldtmpb1"]."', '".$_GET["memoldthb1"]."')";
$query = "insert into roomtemp (LOCATION, TEMPERATURE, HUMIDITY:) values ('ETAJ-CAMERA', '".$_GET["memoldtmpc1"]."', '".$_GET["memoldhc1"]."')";
$query = "insert into roomtemp (LOCATION, TEMPERATURE, HUMIDITY) values ('BUCATARIE', '".$_GET["memoldtmpbc"]."', '".$_GET["memoldhbc"]."')";
$query = "insert into roomtemp (LOCATION, TEMPERATURE, HUMIDITY) values ('GARAJ', '".$_GET["memoldtmpgj"]."', '".$_GET["memoldhgj1"]."')";
$query = "insert into roomtemp (LOCATION, TEMPERATURE, HUMIDITY) values ('POOL WATER TEMP.', '".$_GET["memoldpi"]."', '-')";
mysql_query($query,$link);
mysql_close($link);
header("Location: index.php");
?>
Now... the information I found on google, are very contradictory. Some say, that for the variable field it has to be something like: .$_GET["variablename"] and some say it should be: .$_POST["variablename].
The Arduino code, the same... POST or GET..
the arduino code looks like this:
...
if (client.connect("www.*****.*************.com",80)) { // REPLACE WITH YOUR SERVER ADDRESS
client.println("POST /add_data.php HTTP/1.1");
client.println("Host: *****.*************.com"); // SERVER ADDRESS HERE TOO
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
}
if (client.connected()) {
client.stop(); // DISCONNECT FROM THE SERVER
}
delay(3000);
Thank you for your help!
Adrian.