You are on page 1of 3

koding

#include "SPI.h"
#include "Ethernet.h"

const int temperaturePin = A0;


byte mac[] = { 0x90, 0xA2, 0xDB, 0x0F, 0x3A, 0xDF };
byte ip[] = { 131, 247, 19, 140 }; //this is the ip address for Ethernet
Shield
byte gateway[] = { 131, 225, 3, 254 };
byte subnet[] = { 255, 255, 252, 0 };
EthernetClient client ;
char server[] = "www.localhost.com";

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
}

void loop()
{
if( client.connect(server, 80))
{
float tem = getTemp();
Serial.println( tem );
client.print( "GET /add.php?");
client.print("tempt1=");
client.print( tem );
client.println( " HTTP/1.1");
client.println( "Host: localhost" );
client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
}
delay( 5000 );
}

float getTemp() {
float voltage, V,t ;
voltage = analogRead(temperaturePin) ;
V = voltage * 0.004882814 ;
t = (V - 0.5) * 100.0;
return t;
}
Conec.php
<?php
function Conection(){
if (!($link=mysql_connect("localhost","root","password"))) {
exit();
}
if (!mysql_select_db("temp_database",$link)){
exit();
}
return $link;
}
?>

Add.php
<?php
include("conec.php");
$link=Conection();
$Sql="INSERT INTO 'temp'('temp1') VALUE ('".$_GET["temp1"]."')";
mysql_query($Sql,$link);
header("Location: insertareg.php");
?>

Insertareg.php
<html>
<head>
<title>Data of Sensor</title>
</head>
<body>
<h1>Data from the temperature sensor</h1>
<form action="add.php" method="get">
<TABLE>
<tr>
<td>Temperature </td>
<td><input type="text" name="temp1" size="20" maxlength="30"></td>
</tr>
</TABLE>
<input type="submit" name="accion" value="Grabar">
</FORM>
<hr>
<?php
include("conec.php");
$link=Conection();
$result=mysql_query("select * from temp order by id desc",$link);
?>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td>&nbsp;Temperature &nbsp;</td>
</tr>
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr><td> &nbsp;%s </td></tr>", $row["temp1"]);
}
mysql_free_result($result);
?>
</table>
</body>
</html>

You might also like