Advertisement
computermuseo

serra v2.0 arduino controllo valori

Apr 6th, 2017
2,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include "DHT.h"
  2. #define DHTPIN 3
  3. #define DHTTYPE DHT11
  4. DHT dht(DHTPIN, DHTTYPE);
  5. #include <EtherCard.h>
  6. int sensorPin = A0;
  7. int sensorValue = 0;
  8.  
  9. static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
  10. static byte myip[] = { 192,168,1,6 };
  11. static byte gwip[] = { 192,168,1,1 };
  12. byte Ethernet::buffer[500];
  13. BufferFiller bfill;
  14.  
  15. int t=0;
  16. int h=0;
  17. int Timer= 0;
  18. int Animation = 0;
  19.  
  20. void setup () {
  21. pinMode(sensorPin, INPUT);
  22. if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
  23. Serial.println( "scheda di rete non rilevata");
  24. ether.staticSetup(myip, gwip);
  25. dht.begin();
  26. }
  27.  
  28. static void ReadDHT11()
  29. {
  30. h = dht.readHumidity();
  31. t = dht.readTemperature();
  32. }
  33. static word homePage() {
  34. bfill = ether.tcpOffset();
  35. bfill.emit_p(PSTR(
  36. "HTTP/1.0 200 OK\r\n"
  37. "Content-Type: text/html\r\n"
  38. "Pragma: no-cache\r\n"
  39. "\r\n"
  40. "<meta http-equiv='refresh' content='30'/>"
  41. "<title>SERRA ARDUINO</title>"
  42. "<h1>Temperatura: $D C <br>umidita esterna: $D %<br> umidita terreno: $D %</h1>"),
  43. t, h,A0);
  44. return bfill.position();
  45. }
  46. void loop () {
  47.  
  48. ReadDHT11();
  49.  
  50. word len = ether.packetReceive();
  51. word pos = ether.packetLoop(len);
  52.  
  53. if (pos)
  54. ReadDHT11();
  55. ether.httpServerReply(homePage());
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement