from referensi http://www.instructables.com/id/Save-data-of-temperature-and-humidity-on-MySQL-wit/
and http://forum.arduino.cc/index.php/topic,124289.0.html
i want to make arduino can send data temp and water level of tank via ethernet.
in this project i use:
PC : OS Windows; appliication Xampp
Arduino : Promini 328 (while flashing i use lib Uno);port A0 and A1 (never converted)
in this project make 3 file php : add.php, conec.php, and insertareg.php.
File add.php :
<?php
include("conec.php");
$link=Conection();
$Sql="insert into ardulevel (temp,level) values ('".$_GET["temp"]."', '".$_GET["level"]."')";
mysql_query($Sql,$link);
header("Location: insertareg.php");
?>
file conec.php :
<?php
function Conection(){
if (!($link=mysql_connect("localhost","root",""))) {
exit();
}
if (!mysql_select_db("arduino",$link)){
exit();
}
return $link;
}
?>
file insertareg.php :
<html>
<head>
<title>Data Sensor</title>
</head>
<body>
<h1>Data dari sensor temperature and level</h1>
<form action="add.php" method="get">
<TABLE>
<tr>
<td>Temperature 1</td>
<td><input type="text" name="temp" size="20" maxlength="30"></td>
</tr>
<tr>
<td>Level 1</td>
<td><input type="text" name="level" size="20" maxlength="30"></td>
</tr>
</TABLE>
<input type="submit" name="accion" value="Masukkan">
</FORM>
<hr>
<?php
include("conec.php");
$link=Conection();
$result=mysql_query("select * from ardulevel order by id desc",$link);
?>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td> Waktu 1 </td>
<td> Temperature 1 </td>
<td> Level 1 </td>
</tr>
<?php
while($row = mysql_fetch_array($result)) {
/*printf("<tr><td> %s </td><td> %s </td></tr>", $row["waktu"], $row["temp"], $row["level"]);*/
printf("<tr><td> %s </td><td> %s </td><td> %s </td></tr>", $row["waktu"], $row["temp"], $row["level"]);
}
mysql_free_result($result);
?>
</table>
</body>
</html>
and the sketch of arduino :
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 3, 2); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
String HTTP_req; // stores the HTTP request
boolean LED_status = 0; // state of LED, off by default
int tempValue = 0;
int levelValue = 0;
void setup()
{
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
Serial.begin(9600); // for diagnostics
}
void loop()
{
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
HTTP_req += c; // save the HTTP request 1 char at a time
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
tempValue = analogRead(A0);
levelValue = analogRead(A1);
Serial.println(tempValue);
Serial.println(levelValue);
client.print( "GET /ard/add.php?"); // php??
client.print("temp=");
client.print(tempValue);
client.print("&&");
client.print("level=");
client.print(levelValue);
client.println( " HTTP/1.1");
client.println( "Host: localhost" );//ur web server
client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
///
Serial.print(HTTP_req);
HTTP_req = ""; // finished with request, empty string
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
I try to add this address manually in the tab firefox :
localhost/ard/add.php?temp=28&&level=207
and the result is data can be inserted in table (update table),and then the address view the ‘insertareg.php’ like this ‘http://localhost/ard/insertareg.php’. look at this pic:

But if I just give the address http://192.168.3.2/ , the result is :

The problem is , how to make the address of http is automatically following the realtime data temp and level? In this case, if I input ‘192.168.3.2’ on address tab ,then arduino can send the real time data A0 and A1,may be per 5 second, to make address :
localhost/ard/add.php?temp=x&&level=y.
where, x and y in here data temp and level.
Because I think in the sketch of my arduino can’t run this proses. Thx a lot for your help…
soryy for my english,,,cos im indonesian...![]()