Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define wyswietlacz
- #define zegar
- #ifdef zegar
- #include <Wire.h>
- #include <DS3231.h>
- #endif
- #ifdef wyswietlacz
- #include <SPI.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_PCD8544.h>
- #endif
- #include <EtherCard.h>
- #include "DHT.h"
- #define DHTPIN A2
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
- static byte myip[] = { 192,168,0,254 };
- static byte gwip[] = { 192,168,0,1 };
- byte Ethernet::buffer[500];
- BufferFiller bfill;
- #ifdef wyswietlacz
- Adafruit_PCD8544 display = Adafruit_PCD8544(2, 3, 4, 6, 5);
- #endif
- #ifdef zegar
- DS3231 clock;
- RTCDateTime dt;
- #endif
- int temp = 0;
- int wilg = 0;
- int tempF = 0;
- int Timer= 0;
- #ifdef wyswietlacz
- boolean change = false;
- int Ctime = 0;
- #endif
- #ifdef zegar
- unsigned char godz = 0;
- unsigned char minu = 0;
- #endif
- void setup ()
- {
- #ifdef zegar
- clock.begin();
- #endif
- if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
- {
- Serial.println("Brak polaczenia");
- }
- ether.staticSetup(myip, gwip);
- dht.begin();
- #ifdef wyswietlacz
- display.begin();
- display.setContrast(70);
- display.clearDisplay();
- #endif
- }
- static void OdczytDanych()
- {
- #ifdef zegar
- dt = clock.getDateTime();
- wilg = dht.readHumidity();
- godz = dt.hour;
- minu = dt.minute;
- #endif
- temp = dht.readTemperature();
- tempF = dht.readTemperature(true);
- }
- #ifdef zegar
- static word homePage()
- {
- bfill = ether.tcpOffset();
- bfill.emit_p(PSTR(
- "HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "\r\n"
- "<html>"
- "<head>"
- "<meta http-equiv=Content-Type content=text/html; charset=UTF-8 />"
- "<title>"
- "Serwer Karola"
- "</title></head>"
- "<body style=background-color:#B5FFFF;text-align:CENTER;font-family:cursive>"
- "<h1 style=font-size:35px>Serwer</h1>"
- "<p style=font-size:25px;>Temperatura: <a style=color:red>$D°C $D°F</a></p>"
- "<p style=font-size:25px;>Wilgotność: <a style=color:blue>$D%</a></p>"
- "<p style=font-size:25px;>Czas: <a style=color:green>$D:$D</a></p>"
- "</body>"),
- temp, tempF, wilg, godz, minu);
- return bfill.position();
- }
- #else
- static word homePage()
- {
- bfill = ether.tcpOffset();
- bfill.emit_p(PSTR(
- "HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "\r\n"
- "<html>"
- "<head>"
- "<meta http-equiv=Content-Type content=text/html; charset=UTF-8 />"
- "<title>"
- "Serwer Karola"
- "</title></head>"
- "<body style=background-color:#B5FFFF;text-align:CENTER;font-family:cursive>"
- "<h1 style=font-size:35px>Serwer</h1>"
- "<p style=font-size:25px;>Temperatura: <a style=color:red>$D°C $D°F</a></p>"
- "<p style=font-size:25px;>Wilgotność: <a style=color:blue>$D%</a></p>"
- "</body>"),
- temp, tempF, wilg);
- return bfill.position();
- }
- #endif
- void loop ()
- {
- #ifdef wyswietlacz
- display.setRotation(2); // rotate 180 degrees counter clockwise, can also use values of 2 and 3 to go further.
- display.setTextSize(1);
- display.setTextColor(BLACK);
- display.setCursor(3,3);
- display.println("TEMPE-");
- display.setCursor(4,12);
- display.println("RATURA");
- display.setCursor(47,3);
- display.println("WILGO-");
- display.setCursor(47,12);
- display.println("TNOSC");
- display.drawLine(42, 0, 42, 48, BLACK);
- display.setTextSize(2);
- display.setCursor(4,28);
- if (Ctime >= 20)
- {
- change = !change;
- Ctime = 0;
- }
- Ctime = Ctime + 1;
- if (change == false)
- {
- display.print(tempF);
- display.print("F");
- }
- else
- {
- display.print(temp);
- display.print("C");
- }
- display.setCursor(47,28);
- display.print(wilg);
- display.print("%");
- display.display();
- delay(1000);
- #endif
- Timer = Timer+1;
- if(Timer==1)
- {
- OdczytDanych();
- }
- if(Timer==1100)
- {
- Timer=0;
- }
- word len = ether.packetReceive();
- word pos = ether.packetLoop(len);
- if (pos)
- {
- OdczytDanych();
- ether.httpServerReply(homePage());
- #ifdef wyswietlacz
- display.clearDisplay();
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment