Advertisement
Guest User

Untitled

a guest
Mar 19th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. byte mac[] = { 0x00, 0xAB, 0xBA, 0xBC, 0xDD, 0x02 };
  5. EthernetClient client;
  6. String data;
  7. int t;
  8. int h;
  9.  
  10. void setup() {
  11. Serial.begin(9600);
  12. if (Ethernet.begin(mac) == 0) {
  13. Serial.println("Failed to configure Ethernet using DHCP");
  14. }
  15.  
  16. Serial.println("still working here");
  17.  
  18.  
  19. }
  20.  
  21.  
  22. void loop() {
  23. t = 10;
  24. h = 24;
  25.  
  26. data = "temp1=";
  27.  
  28. data.concat(t);
  29.  
  30. data.concat("&hum1=");
  31.  
  32. data.concat(h);
  33.  
  34.  
  35. if (client.connect("www.smartwater.x10host.com",80)) {
  36. Serial.println(data);
  37. client.print("POST /add.php HTTP/1.1n");
  38. client.print("Host: www.smartwater.x10host.comn");
  39. client.print("Connection: closen");
  40. client.print("Content-Type: application/x-www-form-urlencodedn");
  41. client.print("Content-Length: ");
  42. client.print(data.length());
  43. client.print("nn");
  44. client.print(data);
  45. Serial.println("Successfull");
  46.  
  47.  
  48. }
  49.  
  50. if (client.connected()) {
  51. client.stop();
  52. }
  53.  
  54. delay(20000);
  55. }
  56.  
  57. <?php
  58. include("connect.php");
  59.  
  60. $link=Connection();
  61.  
  62. $temp1=$_POST["data"];
  63. $hum1=$_POST["serial_number"];
  64.  
  65. $query = "INSERT INTO `Main` (`data`, `serial_number`)
  66. VALUES ('".$temp1."','".$hum1."')";
  67.  
  68. mysql_query($query,$link);
  69. mysql_close($link);
  70.  
  71. header("Location: index.php");
  72. ?>
  73.  
  74. <?php
  75.  
  76. function Connection(){
  77. $server="localhost";
  78. $user="smartwat_arduino";
  79. $pass="*****";
  80. $db="smartwat_Main";
  81.  
  82. $connection = mysql_connect($server, $user, $pass);
  83.  
  84. if (!$connection) {
  85. die('MySQL ERROR: ' . mysql_error());
  86. }
  87.  
  88. mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );
  89.  
  90. return $connection;
  91. }
  92. ?>
  93.  
  94. <?php
  95.  
  96. include("connect.php");
  97.  
  98. $link=Connection();
  99.  
  100. $result=mysql_query("SELECT * FROM `Main` ORDER BY `timeStamp` DESC",$link);
  101. ?>
  102.  
  103. <html>
  104. <head>
  105. <title>Data</title>
  106. </head>
  107. <body>
  108. <h1>Stuff</h1>
  109.  
  110. <table border="1" cellspacing="1" cellpadding="1">
  111. <tr>
  112. <td>&nbsp;Timestamp&nbsp;</td>
  113. <td>&nbsp;Data&nbsp;</td>
  114. <td>&nbsp;Serial Number&nbsp;</td>
  115.  
  116. </tr>
  117.  
  118. <?php
  119. if($result!==FALSE){
  120. while($row = mysql_fetch_array($result)) {
  121. printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td></tr>",
  122. $row["timeStamp"], $row["data"], $row["serial_number"]);
  123. }
  124. mysql_free_result($result);
  125. mysql_close();
  126. }
  127. ?>
  128.  
  129. </table>
  130. </body>
  131. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement