Advertisement
Guest User

Untitled

a guest
May 24th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <dht.h>
  4. float humavg=0;
  5.  
  6. dht DHT;
  7. #define DHT22_PIN 7
  8. // the media access control (ethernet hardware) address for the shield:
  9. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  10. //the IP address for the shield:
  11. IPAddress ip(192,168,1,108);
  12. IPAddress server(128,104,201,67);
  13. EthernetClient client;
  14. void setup()
  15. {
  16. Ethernet.begin(mac, ip);
  17. Serial.begin(9600);
  18. if (Ethernet.begin(mac) == 0) {
  19. Serial.println("Couldnt configure");
  20. }
  21. }
  22. void loop() {
  23. int chk = DHT.read22(DHT22_PIN);
  24. humavg=0;
  25. for(int x = 0; x < 1000; x++) {
  26. float hum = DHT.humidity;
  27. humavg=humavg+hum;;
  28. }
  29. humavg=humavg/1000;
  30. float temp = DHT.temperature;
  31. float hum = DHT.humidity;
  32. Serial.println(humavg);
  33. Serial.println(temp);
  34. Serial.println(hum);
  35. // Connect to the server (your computer or web page)
  36. if (client.connect(server, 80)) {
  37. client.print("GET /write_data.php?"); // This
  38. client.print("temperature="); // This
  39. client.print(temp);
  40. client.print("C");
  41. client.print("&&"); // Empty line
  42. client.print("humidity="); // This
  43. client.print(hum);
  44. client.print("%");
  45. client.println(" HTTP/1.1"); // Part of the GET request
  46. client.println("Host: test-min.me.wisc.edu");// IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
  47. client.println("Connection: close");
  48. client.println(); // Empty line
  49. client.println(); // Empty line
  50. client.stop(); // Closing connection to server
  51. }
  52.  
  53.  
  54.  
  55. else {
  56. // If Arduino can't connect to the server (your computer or web page)
  57. Serial.println("--> connection failed\n");
  58. }
  59.  
  60. // Give the server some time to recieve the data and store it. I used 10 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
  61. delay(50000);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement