Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
- byte ip[] = { 192, 168, 1, 178 }; // ip in lan
- byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
- byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
- EthernetServer server(80); //server port
- String readString;
- int ledPin[] = {
- 2, 3, 4, 5, 6, 7, 8, 9, A5, A4, A3, A2, A1, A0 };
- int pinCount = 14;
- void setup(){
- for (int i = 0; i < pinCount; i++) {
- pinMode(ledPin[i], OUTPUT);
- digitalWrite(ledPin[i], HIGH);
- }
- //start Ethernet
- Ethernet.begin(mac, ip, gateway, subnet);
- server.begin();
- //the pin for the servo co
- //enable serial data print
- Serial.begin(9600);
- Serial.println("server LED test 2.2"); // so I can keep track of what is loaded
- }
- 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("<HTML>");
- client.println("<HEAD><TITLE>Home Automation System</TITLE></HEAD>");
- client.println("<BODY>");
- for (int j = 0; j < pinCount; j++) {
- client.println("<p><input type=button value='Channel " + String(j) + " ON' onmousedown=location.href='?ch" + String(j) + "on'>");
- client.println("<input type=button value='Channel " + String(j) + " OFF' onmousedown=location.href='?ch" + String(j) + "off'></p>");
- }
- client.println("</BODY>");
- client.println("</HTML>");
- delay(1);
- //stopping client
- client.stop();
- ///////////////////// control arduino pin
- for (int i = 0; i < pinCount; i++) {
- if (readString.indexOf("?ch" + String(i) + "on") >0)//checks for on
- {
- digitalWrite(ledPin[i], LOW); // set channel i high
- Serial.print("Channel " + String(i) + " On");
- }
- if (readString.indexOf("?ch" + String(i) + "off") >0)//checks for off
- {
- digitalWrite(ledPin[i], HIGH); // set channel i low
- Serial.print("Channel " + String(i) + " Off");
- }
- }
- //clearing string for next read
- readString="";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement