Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //BIBLIOTEKI
- #include <SPI.h> //SPI
- #include <Ethernet2.h> //INTERNET
- #include <TimeLib.h> //CZAS
- #include <Wire.h> //KOMUNIKACJA CZAS
- #include <DS1307RTC.h> //ZEGAR
- #include <IRremote.h> //WYJŚCIE DIODY IR MEGA PIN 9 (OC2B)
- IRsend irsend; //AKTYWACJA DIODY IR
- byte mac[] = {0x90, 0xA2, 0xDA, 0x10, 0x57, 0xB7}; //ADRES MAC
- IPAddress ip(192, 168, 0, 120); //IP SERWERA
- EthernetServer server(80); //PORT SERWERA (W TYM WYPADKU HTTP)
- //STRING
- String dane; //STRING ZAPISUJACY DANE Z SERWERA
- String DOOR = ""; //STRING CZUJNIK DRZWI
- String WINDOWUP = ""; //STRING CZUJNIK OKNO DACHOWE
- String WINDOW = ""; //STRING CZUJNIK OKNO GŁÓWNE
- String LIGHT = ""; //STRING CZUJNIK ŚWIATŁO
- String BIURKO1 = "OFF"; //STRING STANU ŚWIATŁA BIURKO
- String SWIATLO1 = "OFF"; //STRING STANU ŚWIATŁA OGÓLNEGO
- //_______________________________________________________________________________________________________________________________________________________________________________________________________________________________
- void setup()
- {
- pinMode(49, INPUT_PULLUP); // WŁĄCZENIE PINU CZUJNIKA DRZWI
- pinMode(47, INPUT_PULLUP); // WŁĄCZENIE PINU CZUJNIKA OKNO DACHOWE
- pinMode(45, INPUT_PULLUP); // WŁĄCZENIE PINU CZUJNIKA OKNO GÓWNE
- pinMode(43, INPUT_PULLUP); // WŁĄCZENIE PINU CZUJNIKA ŚWIATŁO
- pinMode(33, OUTPUT); // WŁĄCZENIE PINU BIURKA
- pinMode(31, OUTPUT); // WŁĄCZENIE PINU LAMPY
- setSyncProvider(RTC.get); //ZEBRANIE CZASU
- setTime(20,11,0,16,2,2017); //USTAWIENIE CZASU I DATY
- Serial.begin(9600); //SERIAL START
- Ethernet.begin(mac, ip); //ETHERNET START
- server.begin(); //START SERWERA
- Serial.print("SERWER JEST DOSTEPNY: "); //TEST IP
- Serial.println(Ethernet.localIP()); //TEST IP
- }
- //_______________________________________________________________________________________________________________________________________________________________________________________________________________________________
- void loop() {
- //IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
- //ODCZYT STANU CZUJNIKOW
- int DRZWI= digitalRead(49); //ODCZYT STANU CZUJNIKA
- int OKNODACH= digitalRead(47); //ODCZYT STANU CZUJNIKA
- int OKNO= digitalRead(45); //ODCZYT STANU CZUJNIKA
- int SWIATLO= digitalRead(43); //ODCZYT STANU CZUJNIKA
- if (DRZWI == HIGH) //WYSWIETLENIE STANU CZUJNIKA DRZWI (PRZYKŁAD)
- { //
- DOOR.remove(35); //USUŃ 35 ZNAKÓW ZE STRING CZUJNIK DRZWI
- DOOR = "<font color='green'>OTWARTE</font>"; //DODAJ DO STRING CZUJNIK DRZWI FORMUŁĘ OTWARTE W KOLORZE ZIELONY
- } //
- else //W INNYM WYPADKU:
- { //
- DOOR.remove(35); //USUŃ 35 ZNAKÓW ZE STRING CZUJNIK DRZWI
- DOOR = "ZAMKNIETE"; //DODAJ DO STRING CZUJNIK DRZWI FORMUŁĘ ZAMKNIETE
- } //
- if (OKNODACH == HIGH)
- {
- WINDOWUP.remove(35);
- WINDOWUP = "<font color='green'>OTWARTE</font>";
- }
- else
- {
- WINDOWUP.remove(35);
- WINDOWUP = "ZAMKNIETE";
- }
- if (OKNO == HIGH)
- {
- WINDOW.remove(35);
- WINDOW = "<font color='green'>OTWARTE</font>";
- }
- else
- {
- WINDOW.remove(35);
- WINDOW = "ZAMKNIETE";
- }
- if (SWIATLO == HIGH)
- {
- LIGHT.remove(36);
- LIGHT = "ZGASZONE";
- }
- else
- {
- LIGHT.remove(36);
- LIGHT = "<font color='green'>ZAPALONE</font>";
- }
- //IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
- //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- //USTAWIENIA CZASOWE
- /*if (hour() == godzina && minute() == minuty)
- {
- digitalWrite (pin,stan);
- }
- */
- //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- //..............................................................................................................................................................................................................................
- //INTERNET LAN
- EthernetClient client = server.available();
- if (client) {
- Serial.println("NOWY KLIENT");
- boolean currentLineIsBlank = true;
- while (client.connected())
- {
- if (client.available())
- {
- char c = client.read(); // ODBIERANIE DANYCH
- dane += c; // ZAPIS DANYCH
- Serial.write(c); // WYSWIETLANIE DANYCH
- if (c == '\n' && currentLineIsBlank)
- {
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //STANDARTOWA ODPOWIEDŹ BEZ REFRESH
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: close");
- client.println();
- client.println("<!DOCTYPE HTML>");
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //WSTĘP STRONY WWW
- client.println("<head><title>POKOJ</title></head>");
- client.println("<meta http-equiv=Content-Type content='text/html; charset=iso-8859-2'>");
- client.println("<body bgcolor='black' text='red'>");
- client.println("<form method='get'>");
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //TABELA 1 DATA GODZINA WŁĄCZNIKI
- client.println("<table border='1' align='left'>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>DATA:</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(year());
- client.println("</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(month());
- client.println("</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(day());
- client.println("</td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='ON' name='TV'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='INPUT' name='TV'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='MENU' name='TV'></td>");
- client.println("</tr>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>GODZINA:</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(hour());
- client.println("</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(minute());
- client.println("</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(second());
- client.println("</td>");
- client.println("<td align='center' width='150' height='50'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='GORA' name='TV'></td>");
- client.println("<td align='center' width='150' height='50'></td>");
- client.println("</tr>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>BIURKO</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(BIURKO1);
- client.println("</td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='ON' name='BIURKO'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='OFF' name='BIURKO'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='LEWA' name='TV'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='OK' name='TV'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='PRAWA' name='TV'></td>");
- client.println("</tr>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>SWIATLO</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(SWIATLO1);
- client.println("</td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='ON' name='SWIATLO'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='OFF' name='SWIATLO'></td>");
- client.println("<td align='center' width='150' height='50'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='DOL' name='TV'></td>");
- client.println("<td align='center' width='150' height='50'><input type='submit' value='EXIT' name='TV'></td>");
- client.println("</tr>");
- client.println("</table>");
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //TEBELA 2 STAN CZUJNIKÓW
- client.println("<table border='1' align='right'>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>CZUJNIK</td>");
- client.println("<td align='center' width='150' height='50'>STAN</td>");
- client.println("</tr>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>DRZWI</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(DOOR);
- client.println("</td>");
- client.println("</tr>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>OKNO DACH</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(WINDOWUP);
- client.println("</td>");
- client.println("</tr>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>OKNO</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(WINDOW);
- client.println("</td>");
- client.println("</tr>");
- client.println("<tr>");
- client.println("<td align='center' width='150' height='50'>SWIATLO</td>");
- client.println("<td align='center' width='150' height='50'>");
- client.println(LIGHT);
- client.println("</td>");
- client.println("</tr>");
- client.println("</table>");
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //KONEC WWW
- client.println("</form></body></html>");
- //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- break;
- } //KONIEC ODPOWIEDZI
- if (c == '\n')
- {
- //NOWA LINIA
- currentLineIsBlank = true;
- }
- else if (c != '\r')
- {
- //NOWY ZNAK
- currentLineIsBlank = false;
- }
- } //KONIEC client.available
- } //KONIEC client.connected
- delay(1); //ODCZEKANIE NA PRZEJŚCIE DANYCH
- client.stop();
- Serial.println("ROZLOCZONO");
- } // KONIEC client
- //..............................................................................................................................................................................................................................
- //((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
- //PROGRAM TV
- if(dane.indexOf("/?TV=ON HTTP/1.1") > 0) //ZNALEZIENIE FRAGMENTU ZAPYTANIA KTÓRE URUCHAMIA TV (PRZYKŁDOWO)
- { //
- for (int i = 0; i < 3; i++) //PĘTLA POWTÓRZENIA KODU NADANIA IR (EKSPERYMENTALNIE, PRZY 1-KROTNYM URUCHOMIENIU TV NIE ŁAPAŁO)
- { //
- Serial.println("ON"); //TEST SERIAL
- irsend.sendNEC(551489775, 32); //WYSYŁKA KODU IR
- delay(30); //PRZERWA MIEDZY KOLEJNYMI WYSYŁKAMI KODU IR
- } //
- dane=""; //WYCZYSZCZENIE DANYCH ODEBRANYCH ZE STRONY (BEZ TEGO KOD BYŁ CIĄGLE POWTARZANY GDYŻ W STRING dane DANE CIĄGLE ISTNIAŁY I BYŁY WYKRYWANE)
- } //
- if(dane.indexOf("/?TV=INPUT HTTP/1.1") > 0)
- {
- for (int i = 0; i < 3; i++)
- {
- Serial.println("INPUT");
- irsend.sendNEC(551538735, 32);
- delay(30);
- }
- dane="";
- }
- if(dane.indexOf("/?TV=MENU HTTP/1.1") > 0)
- {
- for (int i = 0; i < 3; i++)
- {
- Serial.println("MENU");
- irsend.sendNEC(551535165, 32);
- delay(30);
- }
- dane="";
- }
- if(dane.indexOf("/?TV=GORA HTTP/1.1") > 0)
- {
- Serial.println("GORA");
- irsend.sendNEC(551486205, 32);
- delay(30);
- dane="";
- }
- if(dane.indexOf("/?TV=DOL HTTP/1.1") > 0)
- {
- Serial.println("DOL");
- irsend.sendNEC(551518845, 32);
- delay(30);
- dane="";
- }
- if(dane.indexOf("/?TV=LEWA HTTP/1.1") > 0)
- {
- Serial.println("LEWA");
- irsend.sendNEC(551542815, 32);
- delay(30);
- dane="";
- }
- if(dane.indexOf("/?TV=PRAWA HTTP/1.1") > 0)
- {
- Serial.println("PRAWA");
- irsend.sendNEC(551510175, 32);
- delay(30);
- dane="";
- }
- if(dane.indexOf("/?TV=OK HTTP/1.1") > 0)
- {
- for (int i = 0; i < 3; i++)
- {
- Serial.println("OK");
- irsend.sendNEC(551494365, 32);
- delay(30);
- }
- dane="";
- }
- if(dane.indexOf("/?TV=EXIT HTTP/1.1") > 0)
- {
- for (int i = 0; i < 3; i++)
- {
- Serial.println("EXIT");
- irsend.sendNEC(551541285, 32);
- delay(30);
- }
- dane="";
- }
- //((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
- //))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
- //PROGRAM WŁĄCZNIKÓW
- if(dane.indexOf("?BIURKO=ON HTTP/1.1") > 0) //ZNALEZIENIE FRAGMENTU ZAPYTANIA KTÓRE URUCHAMIA LAMPKE NA BIURKU (PRZYKŁDOWO)
- { //
- digitalWrite (33,HIGH); //USTAW PIN LAMPKI NA WYSOKI
- BIURKO1.remove(30); //USUŃ 30 ZNAKÓW ZE STANU ŚWIATŁA BIURKO
- BIURKO1 = "<font color='green'>ON</font>"; //DODAJ DO STRING STANU ŚWIATŁA BIURKO FORMUŁĘ ON W KOLORZE ZIELONY
- delay(1000); //ODCZEKAJ 1 SEKUNDĘ
- Serial.println("BIURKO=ON"); //TEST SERIAL
- dane=""; //WYCZYŚĆ DANE STRONY WWW
- } //
- if(dane.indexOf("/?BIURKO=OFF HTTP/1.1") > 0)
- {
- digitalWrite (33,LOW);
- BIURKO1.remove(30);
- BIURKO1 = "OFF";
- delay(1000);
- Serial.println("BIURKO=OFF");
- dane="";
- }
- if(dane.indexOf("/?SWIATLO=ON HTTP/1.1") > 0)
- {
- digitalWrite (31,HIGH);
- SWIATLO1.remove(30);
- SWIATLO1 = "<font color='green'>ON</font>";
- delay(1000);
- Serial.println("SWIATLO=ON");
- dane="";
- }
- if(dane.indexOf("/?SWIATLO=OFF HTTP/1.1") > 0)
- {
- digitalWrite (31,LOW);
- SWIATLO1.remove(30);
- SWIATLO1 = "OFF";
- delay(1000);
- Serial.println("SWIATLO=OFF");
- dane="";
- }
- //))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
- }// KONIEC void loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement