Guest User

Untitled

a guest
Jan 1st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2.  
  3. $db_name = "aquarium";
  4. $user = "root";
  5. $password = "root";
  6. $host = "localhost";
  7.  
  8. $con = mysqli_connect($host,$user,$password,$db_name);
  9.  
  10. // Check connection
  11. if (mysqli_connect_errno()) {
  12. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  13. }
  14. $result = mysqli_query($con,"SELECT value FROM light WHERE id='1'");
  15.  
  16. while($row = mysqli_fetch_array($result)) {
  17. echo $row['value'];
  18. echo "<br>";
  19. }
  20.  
  21. ?>
  22.  
  23. #include <Ethernet.h>
  24. #include <SPI.h>
  25.  
  26. byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x2A, 0x8D };
  27. byte ip[] = { 192, 168, 0, 46 };
  28. byte gw[] = {192, 168, 0, 1};
  29. byte subnet[] = { 255, 255, 255, 0 };
  30.  
  31. IPAddress server(192,168,0,101);
  32. EthernetClient client;
  33.  
  34.  
  35. void setup()
  36. {
  37.  
  38. Ethernet.begin(mac, ip, gw, gw, subnet);
  39. Serial.begin(9600);
  40.  
  41. }
  42.  
  43. void loop()
  44. {
  45. Serial.println("Program running...");
  46. delay(5000);
  47. readValue();
  48. }
  49.  
  50. void readValue()
  51. {
  52. Serial.println();
  53. delay(1000); //Keeps the connection from freezing
  54.  
  55. if (client.connect(server ,8080)) {
  56. Serial.println("Connected");
  57.  
  58. //client.print("GET 192.168.0.101:8080/aquarium_light_read.php ");
  59. client.print("GET /aquarium_light_read.php ");
  60.  
  61. Serial.println("The value of light is ");
  62.  
  63. while (client.available())
  64. {
  65. Serial.print(client.read());
  66. }
  67.  
  68. Serial.println("Finish");
  69.  
  70. client.println(" HTTP/1.1");
  71. client.println("Host: 192,168,0,101");
  72. client.println("Connection: close");
  73. client.println();
  74. Serial.println();
  75. }
  76.  
  77. else
  78. {
  79. Serial.println("Connection unsuccesful");
  80. }
  81. //stop client
  82. client.stop();
  83. while(client.status() != 0)
  84. {
  85. delay(5);
  86. }
  87. }
  88.  
  89. Program running...
  90.  
  91. Connected
  92. The value of light is
  93. Finish
Add Comment
Please, Sign In to add comment