Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = { 0x00, 0xAB, 0xBA, 0xBC, 0xDD, 0x02 };
- EthernetClient client;
- String data;
- int t;
- int h;
- void setup() {
- Serial.begin(9600);
- if (Ethernet.begin(mac) == 0) {
- Serial.println("Failed to configure Ethernet using DHCP");
- }
- Serial.println("still working here");
- }
- void loop() {
- t = 10;
- h = 24;
- data = "temp1=";
- data.concat(t);
- data.concat("&hum1=");
- data.concat(h);
- if (client.connect("www.smartwater.x10host.com",80)) {
- Serial.println(data);
- client.print("POST /add.php HTTP/1.1n");
- client.print("Host: www.smartwater.x10host.comn");
- client.print("Connection: closen");
- client.print("Content-Type: application/x-www-form-urlencodedn");
- client.print("Content-Length: ");
- client.print(data.length());
- client.print("nn");
- client.print(data);
- Serial.println("Successfull");
- }
- if (client.connected()) {
- client.stop();
- }
- delay(20000);
- }
- <?php
- include("connect.php");
- $link=Connection();
- $temp1=$_POST["data"];
- $hum1=$_POST["serial_number"];
- $query = "INSERT INTO `Main` (`data`, `serial_number`)
- VALUES ('".$temp1."','".$hum1."')";
- mysql_query($query,$link);
- mysql_close($link);
- header("Location: index.php");
- ?>
- <?php
- function Connection(){
- $server="localhost";
- $user="smartwat_arduino";
- $pass="*****";
- $db="smartwat_Main";
- $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;
- }
- ?>
- <?php
- include("connect.php");
- $link=Connection();
- $result=mysql_query("SELECT * FROM `Main` ORDER BY `timeStamp` DESC",$link);
- ?>
- <html>
- <head>
- <title>Data</title>
- </head>
- <body>
- <h1>Stuff</h1>
- <table border="1" cellspacing="1" cellpadding="1">
- <tr>
- <td> Timestamp </td>
- <td> Data </td>
- <td> Serial Number </td>
- </tr>
- <?php
- if($result!==FALSE){
- while($row = mysql_fetch_array($result)) {
- printf("<tr><td> %s </td><td> %s </td><td> %s </td></tr>",
- $row["timeStamp"], $row["data"], $row["serial_number"]);
- }
- mysql_free_result($result);
- mysql_close();
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement