Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <dht.h>
- float humavg=0;
- dht DHT;
- #define DHT22_PIN 7
- // the media access control (ethernet hardware) address for the shield:
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- //the IP address for the shield:
- IPAddress ip(192,168,1,108);
- IPAddress server(128,104,201,67);
- EthernetClient client;
- void setup()
- {
- Ethernet.begin(mac, ip);
- Serial.begin(9600);
- if (Ethernet.begin(mac) == 0) {
- Serial.println("Couldnt configure");
- }
- }
- void loop() {
- int chk = DHT.read22(DHT22_PIN);
- humavg=0;
- for(int x = 0; x < 1000; x++) {
- float hum = DHT.humidity;
- humavg=humavg+hum;;
- }
- humavg=humavg/1000;
- float temp = DHT.temperature;
- float hum = DHT.humidity;
- Serial.println(humavg);
- Serial.println(temp);
- Serial.println(hum);
- // Connect to the server (your computer or web page)
- if (client.connect(server, 80)) {
- client.print("GET /write_data.php?"); // This
- client.print("temperature="); // This
- client.print(temp);
- client.print("C");
- client.print("&&"); // Empty line
- client.print("humidity="); // This
- client.print(hum);
- client.print("%");
- client.println(" HTTP/1.1"); // Part of the GET request
- 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")
- client.println("Connection: close");
- client.println(); // Empty line
- client.println(); // Empty line
- client.stop(); // Closing connection to server
- }
- else {
- // If Arduino can't connect to the server (your computer or web page)
- Serial.println("--> connection failed\n");
- }
- // 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.
- delay(50000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement