/* Door Sjoerd de Jong Openen en sluiten gordijnen */ #include #include #include Servo microservo; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };//physical mac address byte ip[] = { 192, 168, 240, 7 }; //ip in lan (that's what you need to use in your browser.("192.168.1.178") byte gateway[] = { 192, 168, 240, 254 }; //internet access via router byte subnet[] = { 255, 255, 255, 0 };//subnet mask EthernetServer server(80);//server port String readString; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } microservo.attach(7); microservo.writeMicroseconds(1400); //niet bewegen bij start // start the Ethernet connection and the server: Ethernet.begin(mac, ip, gateway, subnet); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); } void loop() { // Create a client connection EthernetClient client = server.available(); if (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); } //if HTTP request has ended if (c == '\n') { Serial.println(readString); //print to serial monitor for debuging client.println("HTTP/1.1 200 OK"); //send new page client.println("Content-Type: text/html"); client.println(); client.println(""); client.println(""); client.println(""); client.println(""); client.println("Gordijnen Peerlenburg open/dicht"); client.println(""); client.println(""); client.println("

Gordijnen open of dicht

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

Servo op pin 7,

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

"); client.println("stop

"); client.println("dicht
"); client.println("
"); client.println(""); client.println(""); delay(1); //stopping client client.stop(); //controls the Arduino if you press the buttons if (readString.indexOf("?open") >0) { // in steps of 1 degree microservo.writeMicroseconds(2000); //Open (linksom) delay (10000); //tien seconden laten lopen microservo.writeMicroseconds(1400); //stop } if (readString.indexOf("?dicht") >0) { microservo.writeMicroseconds(1000); //Dicht (rechtsom) delay (10000); //tien seconden laten lopen microservo.writeMicroseconds(1400); //stop } if (readString.indexOf("?stop") >0) { microservo.writeMicroseconds(1400); //stop } //clearing string for next read readString=""; } } } } }