Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EtherCard.h>
- // ethernet mac address - must be unique on your network
- static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
- // ethernet interface ip address
- static byte myip[] = { 192,168,1,199 };
- // gateway ip address
- static byte gwip[] = { 192,168,1,252 };
- byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
- // Using a Variable for the Pin, but it is not necessary
- const int red_pin = 2;
- const int orange_pin = 4;
- const int green_pin = 6;
- // Some stuff for responding to the request
- char* on = "ON";
- char* off = "OFF";
- char* statusLabel;
- char* buttonLabel;
- // Small web page to return so the request is completed
- char page[] PROGMEM =
- "HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "Retry-After: 600\r\n"
- "\r\n"
- "<html>"
- "<head><title>"
- "Arduino 192.168.1.199"
- "</title></head>"
- "<body>"
- "<h3>Arduino 192.168.1.199</h3>"
- "</body>"
- "</html>"
- ;
- void setup(){
- Serial.begin(9600); // open the serial port at 9600 bps:
- // Set Pin2 to be an Output
- pinMode(red_pin, OUTPUT);
- // Set Pin4 to be an Output
- pinMode(orange_pin, OUTPUT);
- // Set Pin6 to be an Output
- pinMode(green_pin, OUTPUT);
- //test om bij opstarten alle lampen even te laten branden
- digitalWrite(red_pin, LOW);
- digitalWrite(orange_pin, LOW);
- digitalWrite(green_pin, LOW);
- delay(500);
- digitalWrite(red_pin, LOW);
- digitalWrite(orange_pin, LOW);
- digitalWrite(green_pin, HIGH);
- delay(500);
- digitalWrite(red_pin, LOW);
- digitalWrite(orange_pin, HIGH);
- digitalWrite(green_pin, LOW);
- delay(500);
- digitalWrite(red_pin, HIGH);
- digitalWrite(orange_pin, LOW);
- digitalWrite(green_pin, LOW);
- delay(500);
- digitalWrite(red_pin, LOW);
- digitalWrite(orange_pin, LOW);
- digitalWrite(green_pin, LOW);
- // Zorgen dat bij aanzetten Arduino de groene lamp standaard brand
- digitalWrite(green_pin, HIGH);
- // Scary complex intializing of the EtherCard - I don't understand this stuff (yet0
- ether.begin(sizeof Ethernet::buffer, mymac);
- // Set IP using Static
- ether.staticSetup(myip, gwip);
- }
- int ledState = 0;
- int blink = 0;
- //TOGEVOEGD 28-04
- long previousMillis = 0; //houdt de vorige millis bij
- long interval = 1000; //elke 1000 milliseconden willen we ledState veranderen
- void loop()
- {
- word len = ether.packetReceive();
- word pos = ether.packetLoop(len);
- unsigned long currentMillis = millis();
- // state=OK ---> Green LED on
- if(strstr((char *)Ethernet::buffer + pos, "GET /?state=ok") != 0)
- {
- Serial.println("Received state=ok command");
- digitalWrite(red_pin, LOW);
- digitalWrite(orange_pin, LOW);
- digitalWrite(green_pin, HIGH);
- blink = false;
- }
- // state=warning ---> Orange LED on
- if(strstr((char *)Ethernet::buffer + pos, "GET /?state=warning") != 0)
- {
- Serial.println("Received state=warning command");
- digitalWrite(red_pin, LOW);
- digitalWrite(orange_pin, HIGH);
- digitalWrite(green_pin, LOW);
- blink = false;
- }
- // IF state=critical
- if(strstr((char *)Ethernet::buffer + pos, "GET /?state=critical") != 0)
- {
- Serial.println("Received state=critical command");
- digitalWrite(red_pin, LOW);
- digitalWrite(orange_pin, LOW);
- digitalWrite(green_pin, LOW);
- blink = true;
- }
- ////TOGEVOEGD 28-04
- if(blink)
- {
- //1000 milliseconden voorbij? Ja -> verander ledState en schrijf dit naar de LED
- if(currentMillis - previousMillis > interval)
- {
- previousMillis = currentMillis;
- //Vorige keer LOW geschreven? Dan schrijven we nu HIGH en andersom.
- if (ledState == LOW)
- {
- ledState = HIGH;
- }
- else
- {
- ledState = LOW;
- }
- digitalWrite(red_pin, ledState);
- }
- }
- //Return a page so the request is completed.
- memcpy_P(ether.tcpOffset(), page, sizeof page);
- ether.httpServerReply(sizeof page - 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement