Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
55 views

Send Arduino Data To The Web (PHP MySQL D3.js)

The document contains code to create a database table to log temperature and humidity sensor readings over time. It includes code to connect to the database, insert new readings into the table, and display the logged readings in a table on a webpage. Functions are used to connect to the database and insert new records, which are then queried and output to display the sensor readings history.

Uploaded by

Isabella Sanchez
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Send Arduino Data To The Web (PHP MySQL D3.js)

The document contains code to create a database table to log temperature and humidity sensor readings over time. It includes code to connect to the database, insert new readings into the table, and display the logged readings in a table on a webpage. Functions are used to connect to the database and insert new records, which are then queried and output to display the sensor readings history.

Uploaded by

Isabella Sanchez
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

----------------CREATE TABLE

tempLog------------------------------------------------------------------------
CREATE TABLE tempLog (
timeStamp TIMESTAMP NOT NULL PRIMARY KEY,
temperature int(11) NOT NULL,
humidity int(11) NOT NULL,
);

----------------pagina: connect.php
------------------------------------------------------------------------
<?php
function Connection(){
$server="server";
$user="user";
$pass="pass";
$db="database";
$connection = mysql_connect($server, $user, $pass);
if (!$connection) {
die('MySQL ERROR: ' . mysql_error());
}
mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );
return $connection;
}
?>

----------------pagina: add.php
-----------------------------------------------------------------------------
<?php
include("connect.php");
$link=Connection();
$temp1=$_POST["temp1"];
$hum1=$_POST["hum1"];
$query = "INSERT INTO `tempLog` (`temperature`, `humidity`)
VALUES ('".$temp1."','".$hum1."')";
mysql_query($query,$link);
mysql_close($link);
header("Location: index.php");
?>

----------------pagina: index.php
------------------------------------------------------------------------

<?php
include("connect.php");
$link=Connection();
$result=mysql_query("SELECT * FROM `tempLog` ORDER BY `timeStamp` DESC",
$link);
?>

<html>
<head>
<title>Sensor Data</title>
</head>
<body>
<h1>Temperature / moisture sensor readings</h1>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td>&nbsp;Timestamp&nbsp;</td>
<td>&nbsp;Temperature 1&nbsp;</td>
<td>&nbsp;Moisture 1&nbsp;</td>
</tr>
<?php
if($result!==FALSE){
while($row = mysql_fetch_array($result)) {
printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s&nbsp; </td><td>
&nbsp;%s&nbsp; </td></tr>",
$row["timeStamp"], $row["temperature"], $row["humidity"]);
}
mysql_free_result($result);
mysql_close();
}
?>

</table>
</body>
</html>

You might also like