/* Web_Buzzer.pde - example sketch for Webduino library */ #include #include "Ethernet.h" #include "WebServer.h" #include // einstellen der Mac Adresse static uint8_t mac[] = { 0x77, 0x77, 0x77, 0x77, 0x77, 0x77 }; /* all URLs on this server will start with /buzz because of how we * define the PREFIX value. We also will listen on port 80, the * standard HTTP service port */ #define PREFIX "/" WebServer webserver(PREFIX, 3128); /* the piezo speaker on the Danger Shield is on PWM output pin #3 */ #define BUZZER_PIN 4 /* this is the number of microseconds to wait after turning the * speaker on before turning it off. */ int buzzDelay = 0; /* toggle is used to only turn on the speaker every other loop iteration. */ char toggle = 0; /* This command is set as the default command for the server. It * handles both GET and POST requests. For a GET, it returns a simple * page with some buttons. For a POST, it saves the value posted to * the buzzDelay variable, affecting the output of the speaker */ void buzzCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { if (type == WebServer::POST) { bool repeat; char name[16], value[16]; do { /* readPOSTparam returns false when there are no more parameters * to read from the input. We pass in buffers for it to store * the name and value strings along with the length of those * buffers. */ repeat = server.readPOSTparam(name, 16, value, 16); /* this is a standard string comparison function. It returns 0 * when there's an exact match. We're looking for a parameter * named "buzz" here. */ if (strcmp(name, "led") == 0) { /* use the STRing TO Unsigned Long function to turn the string * version of the delay number into our integer buzzDelay * variable */ buzzDelay = strtoul(value, NULL, 10); } } while (repeat); // after procesing the POST data, tell the web browser to reload // the page using a GET method. server.httpSeeOther(PREFIX); return; } /* for a GET or HEAD, send the standard "it's all OK headers" */ server.httpSuccess(); /* we don't output the body for a HEAD request */ if (type == WebServer::GET) { /* store the HTML in program memory using the P macro */ P(message) = "Arduino WebLed by TheGeek" "" "

Arduino WebLed by TheGeek

" "
" "

" "

" "
"; server.printP(message); } } int EthernetResetPin = 9; // the number of the pushbutton pin //const char* hostName(); //int setHostName(const char* newHostName); void setup() { Serial.begin(9600); // initialize the pushbutton pin as an input: pinMode(EthernetResetPin, OUTPUT); digitalWrite(EthernetResetPin, LOW); digitalWrite(EthernetResetPin, HIGH); // set the PWM output for the buzzer to out pinMode(BUZZER_PIN, OUTPUT); delay(5000); // setup the Ehternet library to talk to the Wiznet board EthernetDHCP.begin(mac, 1); /* register our default command (activated with the request of * http://x.x.x.x/buzz */ webserver.setDefaultCommand(&buzzCmd); /* start the server to wait for connections */ webserver.begin(); } void loop() { // dhcp lease anfordern EthernetDHCP.poll(); // process incoming connections one at a time forever webserver.processConnection(); /* every other time through the loop, turn on and off the speaker if * our delay isn't set to 0. */ if ((++toggle & 1) && (buzzDelay > 0)) { digitalWrite(BUZZER_PIN, HIGH); } else{ digitalWrite(BUZZER_PIN, LOW); } }