/* Web Server A simple web server Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 */ //------------------------------------------------------------------------------------------------------- #include #include // Enter a MAC address and IP address for your controller below. byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x48, 0xD3 }; // The IP address will be dependent on your local network: // assign an IP address for the controller: IPAddress ip(192,168,1,20); IPAddress gateway(192,168,1,1); IPAddress subnet(255, 255, 255, 0); // Initialize the Ethernet server library with the port you want to use. EthernetServer server(80); String readString; //------------------------------------------------------------------------------------------------------- //------------------------------------------------- // Any extra codes for Declaration : // Declare Pin 8 as an LED because thats what we will be connecting the LED to.You could use any other pin and would then have to change the pin number. int cikis1 = 2; int cikis2 = 3; //------------------------------------------------- //------------------------------------------------------------------------------------------------------- void setup() { //------------------------------------------------- // Extra Set up code: pinMode(cikis1, OUTPUT); //pin selected to control pinMode(cikis2, OUTPUT); //------------------------------------------------- //------------------------------------------------------------------------------------------------------- //enable serial data print Serial.begin(9600); //start Ethernet Ethernet.begin(mac, ip, gateway, subnet); server.begin(); Serial.print("Server is at "); Serial.println(Ethernet.localIP()); Serial.println("LED Controller Test 1.0"); } //------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------- void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); while (client.connected()) { if (client.available()) { char c = client.read(); //read char by char HTTP request if (readString.length() < 100) { //store characters to string readString += c; //Serial.print(c); Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply //if HTTP request has ended if (c == '\n') { Serial.println(readString); //print to serial monitor for debuging //-------------------------------------------------------------------------------------------------------- // Needed to Display Site: client.println("HTTP/1.1 200 OK"); //send new page client.println("Content-Type: text/html"); client.println(); if (readString.indexOf("ajax_switch") > -1) { // read switch state and send appropriate paragraph text client.println("

"); client.println("Cihaz durumu"); client.println("
"); cikis1kontrol(client); client.println("
"); cikis2kontrol(client); } else { client.println(""); client.println(""); client.println("Ev Otomasyon"); client.println("

"); client.println(""); client.println(""); client.println("

Ev Otomasyon

"); client.println("
"); client.println("
"); client.println(""); //1. kısım client.println("Tv Ac"); client.println(" - "); client.println("Tv Kapat"); client.println("
"); //2.kısım client.println("Kombi Ac"); client.println(" - "); client.println("Kombi Kapat
"); //durum çubuğu client.println(""); client.println("Durum kontrol ediliyor"); client.println(""); client.println(""); } delay(1); //stopping client client.stop(); //------------------------------------------------- // Code which needs to be Implemented: if(readString.indexOf("?cikis1ac") > 0 )//checks for on { digitalWrite(cikis1, HIGH); // set pin 8 high } else{ if(readString.indexOf("?cikis1kapat") >0)//checks for off { digitalWrite(cikis1, LOW); // set pin 8 low Serial.println("Led Off"); } } if(readString.indexOf("?cikis2ac") >0)//checks for on { digitalWrite(cikis2, HIGH); // set pin 8 high Serial.println("Led On"); } else{ if(readString.indexOf("?cikis2kapat") >0)//checks for off { digitalWrite(cikis2, LOW); // set pin 8 low Serial.println("Led Off"); } } //clearing string for next read readString=""; // give the web browser time to receive the data delay(1); // close the connection: client.stop(); Serial.println("client disonnected"); } } } } } } void cikis1kontrol(EthernetClient cl) { if (digitalRead(cikis1)) { cl.println("Tv Açık"); } else { cl.println("Tv Kapali"); } } void cikis2kontrol(EthernetClient cl) { if (digitalRead(cikis2)) { cl.println("Kombi Acik "); } else { cl.println("Kombi Kapali "); } }