Advertisement
Guest User

Untitled

a guest
Jul 16th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. <?php
  2.  
  3. $dbhost = "mysql.commonarchitecture.ca";
  4. $username = "arduinodb";
  5. $password = "*******";
  6. $db = "arduinodb" ;
  7.  
  8. mysql_connect("$dbhost" , "$username" , "$password");
  9. //echo "Connected" ;
  10.  
  11. //select db
  12. mysql_select_db($db);
  13. //echo "Connected to db" ;
  14.  
  15. $sql="SELECT * FROM data";
  16.  
  17. $records=mysql_query($sql);
  18.  
  19. ?>
  20.  
  21. <!DOCTYPE html>
  22. <html>
  23.  
  24. <head>
  25. <title> Consumption Data </title>
  26. </head>
  27.  
  28. <body>
  29.  
  30. <table width="600" border="1" cellpadding="1" cellspacing"1">
  31.  
  32. <tr>
  33.  
  34. <th>Day</th>
  35. <th>Date</th>
  36. <th>Water Consumption (liters per person)</th>
  37.  
  38. <tr>
  39.  
  40. <?php
  41.  
  42. while($data=mysql_fetch_assoc($records)) {
  43.  
  44. echo "<tr>";
  45.  
  46. echo "<td>".$data['id']."</td>";
  47.  
  48. echo "<td>".$data['date']."</td>";
  49.  
  50. echo "<td>".$data['value']."</td>";
  51.  
  52. echo "</tr>";
  53.  
  54. }//end while
  55.  
  56. ?>
  57.  
  58. </table>
  59.  
  60. </body>
  61. </html>
  62.  
  63. #include <SPI.h>
  64. #include <Ethernet.h>
  65.  
  66.  
  67. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  68.  
  69. IPAddress ip(192, 168, *, *);
  70.  
  71. EthernetClient client;
  72.  
  73. char server[] = "www.decathlon.commonarchitecture.ca";
  74.  
  75.  
  76. void setup()
  77. {
  78. Serial.begin(9600);
  79.  
  80. // attempt a DHCP connection:
  81. Serial.println("Attempting to get an IP address using DHCP:");
  82. if (!Ethernet.begin(mac)) {
  83. // if DHCP fails, start with a hard-coded address:
  84. Serial.println("failed to get an IP address using DHCP, trying
  85. manually");
  86. Ethernet.begin(mac, ip);
  87. }
  88.  
  89. Serial.print("My address:");
  90. Serial.println(Ethernet.localIP());
  91. }
  92.  
  93.  
  94. void loop()
  95. {
  96. // connect to the server
  97. if (client.connect(server, 80))
  98. {
  99. // print to serial monitor
  100. Serial.println("connected...");
  101. Serial.println("ARDUINO: forming HTTP request message");
  102.  
  103. // send data the server through GET request
  104. client.print("GET /index.php?value");
  105. client.println(" HTTP/1.1");
  106. client.print("HOST: ");
  107. client.println(server);
  108.  
  109. Serial.println("ARDUINO: HTTP message sent");
  110.  
  111. // give server time to receive request
  112. delay(1000);
  113.  
  114. // get the response from the page and print it to serial port
  115. // to ascertain that request was received properly
  116. if(client.available())
  117. {
  118. Serial.println("ARDUINO: HTTP message received");
  119. Serial.println("ARDUINO: printing received headers and
  120. script response...n");
  121.  
  122. while(client.available())
  123. {
  124. char c = client.read();
  125. Serial.print(c);
  126. }
  127. }
  128. else
  129. {
  130. Serial.println("ARDUINO: no response received / no response
  131. received in time");
  132. }
  133.  
  134. client.stop();
  135. }
  136. // do nothing forever after:
  137. while(true);
  138. }
  139.  
  140. Attempting to get an IP address using DHCP:
  141. My address:192.168.*.*
  142. connected...
  143. ARDUINO: forming HTTP request message
  144. ARDUINO: HTTP message sent
  145. ARDUINO: no response received / no response received in time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement