diff --git a/WebServer.h b/WebServer.h index c8c43c3..ebf3235 100644 --- a/WebServer.h +++ b/WebServer.h @@ -29,9 +29,11 @@ #include #include -#include -#include -#include + +#include +#include + + /******************************************************************** * CONFIGURATION @@ -62,7 +64,7 @@ #endif #ifndef WEBDUINO_FAIL_MESSAGE -#define WEBDUINO_FAIL_MESSAGE "

EPIC FAIL

" +#define WEBDUINO_FAIL_MESSAGE "

Page not found

" #endif #ifndef WEBDUINO_AUTH_REALM diff --git a/examples/Web_AjaxBuzzer/Web_AjaxBuzzer.ino b/examples/Web_AjaxBuzzer/Web_AjaxBuzzer.ino index e546030..889380d 100644 --- a/examples/Web_AjaxBuzzer/Web_AjaxBuzzer.ino +++ b/examples/Web_AjaxBuzzer/Web_AjaxBuzzer.ino @@ -1,14 +1,14 @@ /* Web_Buzzer.pde - example sketch for Webduino library */ -#include "SPI.h" -#include "Ethernet.h" +#include +#include #include "WebServer.h" // CHANGE THIS TO YOUR OWN UNIQUE VALUE static uint8_t mac[6] = { 0x02, 0xAA, 0xBB, 0xCC, 0x00, 0x22 }; // CHANGE THIS TO MATCH YOUR HOST NETWORK -static uint8_t ip[4] = { 192, 168, 1, 210 }; // area 51! +//IPAddress ip(192, 168, 1, 177); /* 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 @@ -96,11 +96,14 @@ void buzzCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) void setup() { + Serial.begin(9600); // set the PWM output for the buzzer to out pinMode(BUZZER_PIN, OUTPUT); // setup the Ehternet library to talk to the Wiznet board - Ethernet.begin(mac, ip); + Ethernet.begin(mac); + //Ethernet.begin(mac, ip); + /* register our default command (activated with the request of * http://x.x.x.x/buzz */ @@ -108,6 +111,8 @@ void setup() /* start the server to wait for connections */ webserver.begin(); + Serial.print("Web server is at "); + Serial.println(Ethernet.localIP()); } void loop() diff --git a/examples/Web_AjaxRGB/Web_AjaxRGB.ino b/examples/Web_AjaxRGB/Web_AjaxRGB.ino index 8e05a8c..2519c5b 100644 --- a/examples/Web_AjaxRGB/Web_AjaxRGB.ino +++ b/examples/Web_AjaxRGB/Web_AjaxRGB.ino @@ -1,18 +1,18 @@ /* Web_AjaxRGB.pde - example sketch for Webduino library */ -#include "SPI.h" -#include "Ethernet.h" +#include +#include #include "WebServer.h" // CHANGE THIS TO YOUR OWN UNIQUE VALUE static uint8_t mac[6] = { 0x02, 0xAA, 0xBB, 0xCC, 0x00, 0x22 }; // CHANGE THIS TO MATCH YOUR HOST NETWORK -static uint8_t ip[4] = { 192, 168, 1, 210 }; // area 51! +//IPAddress ip(192, 168, 1, 177); /* all URLs on this server will start with /rgb because of how we - * define the PREFIX value. We also will listen on port 80, the - * standard HTTP service port */ + define the PREFIX value. We also will listen on port 80, the + standard HTTP service port */ #define PREFIX "/rgb" WebServer webserver(PREFIX, 80); @@ -25,9 +25,9 @@ int blue = 0; //integer for blue darkness int green = 0; //integer for green darkness /* 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 red/green/blue variable, affecting the output of the speaker */ + 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 red/green/blue variable, affecting the output of the speaker */ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) { if (type == WebServer::POST) @@ -37,19 +37,19 @@ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) 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. */ + 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 red/green/blue here. */ + when there's an exact match. We're looking for a parameter + named red/green/blue here. */ if (strcmp(name, "red") == 0) { - /* use the STRing TO Unsigned Long function to turn the string - * version of the color strength value into our integer red/green/blue - * variable */ + /* use the STRing TO Unsigned Long function to turn the string + version of the color strength value into our integer red/green/blue + variable */ red = strtoul(value, NULL, 10); } if (strcmp(name, "green") == 0) @@ -61,12 +61,12 @@ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) blue = strtoul(value, NULL, 10); } } while (repeat); - + // after procesing the POST data, tell the web browser to reload - // the page using a GET method. + // the page using a GET method. server.httpSeeOther(PREFIX); -// Serial.print(name); -// Serial.println(value); + // Serial.print(name); + // Serial.println(value); return; } @@ -78,31 +78,31 @@ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) if (type == WebServer::GET) { /* store the HTML in program memory using the P macro */ - P(message) = -"" - "Webduino AJAX RGB Example" - "" - "" - "" - "" - "" -"" -"" - "
" - "
" - "
" -"" -""; + P(message) = + "" + "Webduino AJAX RGB Example" + "" + "" + "" + "" + "" + "" + "" + "
" + "
" + "
" + "" + ""; server.printP(message); } @@ -114,28 +114,31 @@ void setup() pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); -// Serial.begin(9600); + Serial.begin(9600); // setup the Ehternet library to talk to the Wiznet board - Ethernet.begin(mac, ip); + Ethernet.begin(mac); + //Ethernet.begin(mac, ip); /* register our default command (activated with the request of - * http://x.x.x.x/rgb */ + http://x.x.x.x/rgb */ webserver.setDefaultCommand(&rgbCmd); /* start the server to wait for connections */ webserver.begin(); + Serial.print("Web server is at "); + Serial.println(Ethernet.localIP()); } void loop() { // process incoming connections one at a time forever webserver.processConnection(); -// Serial.print(red); -// Serial.print(" "); -// Serial.print(green); -// Serial.print(" "); -// Serial.println(blue); + // Serial.print(red); + // Serial.print(" "); + // Serial.print(green); + // Serial.print(" "); + // Serial.println(blue); analogWrite(RED_PIN, red); analogWrite(GREEN_PIN, green); analogWrite(BLUE_PIN, blue); diff --git a/examples/Web_AjaxRGB_mobile/Web_AjaxRGB_mobile.ino b/examples/Web_AjaxRGB_mobile/Web_AjaxRGB_mobile.ino index aa49ee2..06fa3d8 100644 --- a/examples/Web_AjaxRGB_mobile/Web_AjaxRGB_mobile.ino +++ b/examples/Web_AjaxRGB_mobile/Web_AjaxRGB_mobile.ino @@ -1,19 +1,20 @@ /* Web_AjaxRGB_mobile.pde - example sketch for Webduino library */ /* - offers web-based slider controllers for RGB led - */ -#include "SPI.h" -#include "Ethernet.h" +#include +#include #include "WebServer.h" + // CHANGE THIS TO YOUR OWN UNIQUE VALUE static uint8_t mac[6] = { 0x02, 0xAA, 0xBB, 0xCC, 0x00, 0x22 }; // CHANGE THIS TO MATCH YOUR HOST NETWORK -static uint8_t ip[4] = { 192, 168, 1, 210 }; // area 51! +//IPAddress ip(192, 168, 1, 177); /* all URLs on this server will start with /rgb because of how we - * define the PREFIX value. We also will listen on port 80, the - * standard HTTP service port */ + define the PREFIX value. We also will listen on port 80, the + standard HTTP service port */ #define PREFIX "/rgb" WebServer webserver(PREFIX, 80); @@ -26,9 +27,9 @@ int blue = 0; //integer for blue darkness int green = 0; //integer for green darkness /* 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 red/green/blue variable, affecting the output of the speaker */ + 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 red/green/blue variable, affecting the output of the speaker */ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) { if (type == WebServer::POST) @@ -38,19 +39,19 @@ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) 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. */ + 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 red/green/blue here. */ + when there's an exact match. We're looking for a parameter + named red/green/blue here. */ if (strcmp(name, "red") == 0) { - /* use the STRing TO Unsigned Long function to turn the string - * version of the color strength value into our integer red/green/blue - * variable */ + /* use the STRing TO Unsigned Long function to turn the string + version of the color strength value into our integer red/green/blue + variable */ red = strtoul(value, NULL, 10); } if (strcmp(name, "green") == 0) @@ -62,12 +63,12 @@ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) blue = strtoul(value, NULL, 10); } } while (repeat); - + // after procesing the POST data, tell the web browser to reload - // the page using a GET method. + // the page using a GET method. server.httpSeeOther(PREFIX); -// Serial.print(name); -// Serial.println(value); + // Serial.print(name); + // Serial.println(value); return; } @@ -79,28 +80,28 @@ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) if (type == WebServer::GET) { /* store the HTML in program memory using the P macro */ - P(message) = -"" - "" - "Webduino RGB" - "" - "" - "" - "" - "" -"" -"" - "

Webduino RGB

" - "
" + P(message) = + "" + "" + "Webduino RGB" + "" + "" + "" + "" + "" + "" + "" + "

Webduino RGB

" + "
" "" "" "" - "
" - "" -""; + "
" + "" + ""; server.printP(message); } @@ -108,32 +109,36 @@ void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) void setup() { + Serial.begin(9600); pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); -// Serial.begin(9600); // setup the Ehternet library to talk to the Wiznet board - Ethernet.begin(mac, ip); + Ethernet.begin(mac); + //Ethernet.begin(mac, ip); + /* register our default command (activated with the request of - * http://x.x.x.x/rgb */ + http://x.x.x.x/rgb */ webserver.setDefaultCommand(&rgbCmd); /* start the server to wait for connections */ webserver.begin(); + Serial.print("Web server is at "); + Serial.println(Ethernet.localIP()); } void loop() { // process incoming connections one at a time forever webserver.processConnection(); -// Serial.print(red); -// Serial.print(" "); -// Serial.print(green); -// Serial.print(" "); -// Serial.println(blue); + // Serial.print(red); + // Serial.print(" "); + // Serial.print(green); + // Serial.print(" "); + // Serial.println(blue); analogWrite(RED_PIN, red); analogWrite(GREEN_PIN, green); analogWrite(BLUE_PIN, blue); diff --git a/examples/Web_Authentication/Web_Authentication.ino b/examples/Web_Authentication/Web_Authentication.ino index 4a2384d..cb7ae8e 100644 --- a/examples/Web_Authentication/Web_Authentication.ino +++ b/examples/Web_Authentication/Web_Authentication.ino @@ -10,10 +10,11 @@ * WEBDUINO_AUTH_REALM before including WebServer.h */ #define WEBDUINO_AUTH_REALM "Weduino Authentication Example" -#include "SPI.h" -#include "Ethernet.h" +#include +#include #include "WebServer.h" + /* CHANGE THIS TO YOUR OWN UNIQUE VALUE. The MAC number should be * different from any other devices on your network or you'll have * problems receiving packets. */ @@ -23,7 +24,7 @@ static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; * the 192.168.0.XXX or 192.168.1.XXX subrange. Pick an address * that's not in use and isn't going to be automatically allocated by * DHCP from your router. */ -static uint8_t ip[] = { 192, 168, 1, 210 }; +//IPAddress ip(192, 168, 1, 177); /* This creates an instance of the webserver. By specifying a prefix * of "", all pages will be at the root of the server. */ @@ -89,11 +90,15 @@ void privateCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) void setup() { - Ethernet.begin(mac, ip); + Serial.begin(9600); + Ethernet.begin(mac); + //Ethernet.begin(mac, ip); webserver.setDefaultCommand(&defaultCmd); webserver.addCommand("index.html", &defaultCmd); webserver.addCommand("private.html", &privateCmd); webserver.begin(); + Serial.print("Web server is at "); + Serial.println(Ethernet.localIP()); } void loop() diff --git a/examples/Web_Buzzer/Web_Buzzer.ino b/examples/Web_Buzzer/Web_Buzzer.ino index 083f315..a937bda 100644 --- a/examples/Web_Buzzer/Web_Buzzer.ino +++ b/examples/Web_Buzzer/Web_Buzzer.ino @@ -1,7 +1,7 @@ /* Web_Buzzer.pde - example sketch for Webduino library */ -#include "SPI.h" -#include "Ethernet.h" +#include +#include #include "WebServer.h" /* CHANGE THIS TO YOUR OWN UNIQUE VALUE. The MAC number should be @@ -13,7 +13,8 @@ static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; * the 192.168.0.XXX or 192.168.1.XXX subrange. Pick an address * that's not in use and isn't going to be automatically allocated by * DHCP from your router. */ -static uint8_t ip[] = { 192, 168, 1, 210 }; +// CHANGE THIS TO MATCH YOUR HOST NETWORK +//IPAddress ip(192, 168, 1, 177); /* 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 @@ -93,11 +94,13 @@ void buzzCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, void setup() { + Serial.begin(9600); // set the PWM output for the buzzer to out pinMode(BUZZER_PIN, OUTPUT); // setup the Ehternet library to talk to the Wiznet board - Ethernet.begin(mac, ip); + Ethernet.begin(mac); + //Ethernet.begin(mac, ip); /* register our default command (activated with the request of * http://x.x.x.x/buzz */ @@ -105,6 +108,8 @@ void setup() /* start the server to wait for connections */ webserver.begin(); + Serial.print("Web server is at "); + Serial.println(Ethernet.localIP()); } void loop() diff --git a/examples/Web_Demo/Web_Demo.ino b/examples/Web_Demo/Web_Demo.ino index bb4a016..ebc7013 100644 --- a/examples/Web_Demo/Web_Demo.ino +++ b/examples/Web_Demo/Web_Demo.ino @@ -1,42 +1,47 @@ /* Web_Demo.pde -- sample code for Webduino server library */ /* - * To use this demo, enter one of the following USLs into your browser. - * Replace "host" with the IP address assigned to the Arduino. - * - * http://host/ - * http://host/json - * - * This URL brings up a display of the values READ on digital pins 0-9 - * and analog pins 0-5. This is done with a call to defaultCmd. - * - * - * http://host/form - * - * This URL also brings up a display of the values READ on digital pins 0-9 - * and analog pins 0-5. But it's done as a form, by the "formCmd" function, - * and the digital pins are shown as radio buttons you can change. - * When you click the "Submit" button, it does a POST that sets the - * digital pins, re-reads them, and re-displays the form. - * - */ - -#include "SPI.h" -#include "Ethernet.h" + To use this demo, enter one of the following USLs into your browser. + Replace "host" with the IP address assigned to the Arduino. + + http://host/ + http://host/json + + This URL brings up a display of the values READ on digital pins 0-9 + and analog pins 0-5. This is done with a call to defaultCmd. + + + http://host/form + + This URL also brings up a display of the values READ on digital pins 0-9 + and analog pins 0-5. But it's done as a form, by the "formCmd" function, + and the digital pins are shown as radio buttons you can change. + When you click the "Submit" button, it does a POST that sets the + digital pins, re-reads them, and re-displays the form. + +*/ + +#include +#include #include "WebServer.h" -// no-cost stream operator as described at -// http://sundial.org/arduino/?page_id=119 -template -inline Print &operator <<(Print &obj, T arg) -{ obj.print(arg); return obj; } + + +// no-cost stream operator as described at http://arduiniana.org/libraries/streaming/ +template inline Print &operator <<(Print &obj, T arg) +{ + obj.print(arg); + return obj; +} + + // CHANGE THIS TO YOUR OWN UNIQUE VALUE static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // CHANGE THIS TO MATCH YOUR HOST NETWORK -static uint8_t ip[] = { 192, 168, 1, 210 }; +//IPAddress ip(192, 168, 1, 177); #define PREFIX "" @@ -55,11 +60,11 @@ void jsonCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, //server.httpSuccess(false, "application/json"); server.httpSuccess("application/json"); - + if (type == WebServer::HEAD) return; - int i; + int i; server << "{ "; for (i = 0; i <= 9; ++i) { @@ -75,7 +80,7 @@ void jsonCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, if (i != 5) server << ", "; } - + server << " }"; } @@ -162,19 +167,23 @@ void formCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { - outputPins(server, type, false); + outputPins(server, type, false); } void setup() { + Serial.begin(9600); // set pins 0-8 for digital input - for (int i = 0; i <= 9; ++i) + for (int i = 0; i <= 9; ++i){ pinMode(i, INPUT); + } pinMode(9, OUTPUT); - Ethernet.begin(mac, ip); + Ethernet.begin(mac); + //Ethernet.begin(mac, ip); webserver.begin(); - + Serial.print("Web server is at "); + Serial.println(Ethernet.localIP()); webserver.setDefaultCommand(&defaultCmd); webserver.addCommand("json", &jsonCmd); webserver.addCommand("form", &formCmd); diff --git a/examples/Web_HelloWorld/Web_HelloWorld.ino b/examples/Web_HelloWorld/Web_HelloWorld.ino index aebf90a..0aaaaee 100644 --- a/examples/Web_HelloWorld/Web_HelloWorld.ino +++ b/examples/Web_HelloWorld/Web_HelloWorld.ino @@ -1,9 +1,12 @@ /* Web_HelloWorld.pde - very simple Webduino example */ -#include "SPI.h" -#include "Ethernet.h" + +#include +#include #include "WebServer.h" + + /* CHANGE THIS TO YOUR OWN UNIQUE VALUE. The MAC number should be * different from any other devices on your network or you'll have * problems receiving packets. */ @@ -14,7 +17,8 @@ static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; * the 192.168.0.XXX or 192.168.1.XXX subrange. Pick an address * that's not in use and isn't going to be automatically allocated by * DHCP from your router. */ -static uint8_t ip[] = { 192, 168, 1, 210 }; + +//IPAddress ip(192, 168, 1, 177); /* This creates an instance of the webserver. By specifying a prefix * of "", all pages will be at the root of the server. */ @@ -39,16 +43,19 @@ void helloCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) * amount of RAM. */ P(helloMsg) = "

Hello, World!

"; - /* this is a special form of print that outputs from PROGMEM */ + /* this is a special form of print that outputs from PROGMEM */ server.printP(helloMsg); } } void setup() { + Serial.begin(9600); + /* initialize the Ethernet adapter */ - Ethernet.begin(mac, ip); - + Ethernet.begin(mac); + //Ethernet.begin(mac, ip); + /* setup our default command that will be run when the user accesses * the root page on the server */ webserver.setDefaultCommand(&helloCmd); @@ -59,6 +66,8 @@ void setup() /* start the webserver */ webserver.begin(); + Serial.print("Web server is at "); + Serial.println(Ethernet.localIP()); } void loop() diff --git a/examples/Web_Image/Web_Image.ino b/examples/Web_Image/Web_Image.ino index cafb149..0616d2e 100644 --- a/examples/Web_Image/Web_Image.ino +++ b/examples/Web_Image/Web_Image.ino @@ -2,27 +2,28 @@ /* For webduino version 1.2 */ /* DISCLAIMER -- the Webduino server can only handle one web connection - * at a time. Because of this, loading the root page on this sketch may - * not correctly show the LED icon if the browser starts requesting that - * picture before the page has finished loading. - * - * This problem should be reduced greatly once the Ethernet library - * has been modified to do proper packet buffering. With the library - * in Arduino 15, each character is sent in its own TCP/IP packet. - * This is very inefficient and means that it takes much longer to - * send a web page than it should. When this bug is fixed, the web - * server will have sent its last data and closed the connection by - * the time the client reads the HTML, so it's ready to handle the - * image request. - */ - -#include "SPI.h" -#include "Ethernet.h" + at a time. Because of this, loading the root page on this sketch may + not correctly show the LED icon if the browser starts requesting that + picture before the page has finished loading. + + This problem should be reduced greatly once the Ethernet library + has been modified to do proper packet buffering. With the library + in Arduino 15, each character is sent in its own TCP/IP packet. + This is very inefficient and means that it takes much longer to + send a web page than it should. When this bug is fixed, the web + server will have sent its last data and closed the connection by + the time the client reads the HTML, so it's ready to handle the + image request. +*/ + +#include +#include #include "WebServer.h" + // CHANGE THIS TO YOUR OWN UNIQUE VALUE static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -static uint8_t ip[] = { 192, 168, 1, 210 }; +//IPAddress ip(192, 168, 1, 177); WebServer webserver("", 80); @@ -43,7 +44,7 @@ void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tai if (type == WebServer::GET) { /* store the HTML in program memory using the P macro */ - P(message) = + P(message) = "Webduino Image Example" "" "

LED Image

" @@ -57,7 +58,7 @@ void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tai void imageCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { /* this data was taken from a PNG file that was converted to a C data structure - * by running it through the directfb-csource application. */ + by running it through the directfb-csource application. */ P(ledData) = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x91, 0x68, @@ -96,11 +97,14 @@ void imageCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, void setup() { + Serial.begin(9600); // setup the Ehternet library to talk to the Wiznet board - Ethernet.begin(mac, ip); + Ethernet.begin(mac); + //Ethernet.begin(mac, ip); + /* register our default command (activated with the request of - * http://x.x.x.x/ */ + http://x.x.x.x/ */ webserver.setDefaultCommand(&defaultCmd); /* register our image output command */ @@ -108,6 +112,8 @@ void setup() /* start the server to wait for connections */ webserver.begin(); + Serial.print("Web server is at "); + Serial.println(Ethernet.localIP()); } void loop() diff --git a/examples/Web_Image/led.png b/examples/Web_Image/led.png deleted file mode 100644 index aa97b62..0000000 Binary files a/examples/Web_Image/led.png and /dev/null differ diff --git a/examples/Web_Net_Setup/System.cpp b/examples/Web_Net_Setup/System.cpp index 25ef78f..4d2d809 100644 --- a/examples/Web_Net_Setup/System.cpp +++ b/examples/Web_Net_Setup/System.cpp @@ -43,12 +43,14 @@ char* System::uptime() return retval; } +/* int System::ramFree () { extern int __heap_start, *__brkval; int v; int a = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); return a; } +*/ int System::ramSize() { int v; diff --git a/examples/Web_Net_Setup/System.h b/examples/Web_Net_Setup/System.h index 13397c4..4df23a2 100644 --- a/examples/Web_Net_Setup/System.h +++ b/examples/Web_Net_Setup/System.h @@ -23,7 +23,7 @@ class System { * Returns the free RAM * @return int: free RAM */ - int ramFree(); + //int ramFree(); /** * Returns the size of the RAM diff --git a/examples/Web_Net_Setup/Web_Net_Setup.pde b/examples/Web_Net_Setup/Web_Net_Setup.ino similarity index 96% rename from examples/Web_Net_Setup/Web_Net_Setup.pde rename to examples/Web_Net_Setup/Web_Net_Setup.ino index 2425433..c0d2298 100644 --- a/examples/Web_Net_Setup/Web_Net_Setup.pde +++ b/examples/Web_Net_Setup/Web_Net_Setup.ino @@ -64,17 +64,20 @@ For more informations about EEPROMAnything.h look at http://playground.arduino.c #define WEBDUINO_FAVICON_DATA "" // no favicon -//#define DEBUG //uncomment for serial debug output -#define USE_SYSTEM_LIBRARY //comment out if you want to save some space (about 1 Byte). You wouldn't see uptime and free RAM if it's commented out. +#define DEBUG //uncomment for serial debug output +//#define USE_SYSTEM_LIBRARY //comment out if you want to save some space (about 1 Byte). You wouldn't see uptime and free RAM if it's commented out. #define SERIAL_BAUD 9600 -#include "SPI.h" // new include + #include "avr/pgmspace.h" // new include -#include "Ethernet.h" +#include +#include #include "WebServer.h" + + /* ############################################################################################################################################################# * Code for the EEPROM related things * @@ -82,7 +85,7 @@ For more informations about EEPROMAnything.h look at http://playground.arduino.c #include #include "EEPROMAnything.h" -#define RESET_PIN 40 //Connect a button to this PIN. If the button is hold, an the device is turned on the default ethernet settings are restored. +#define RESET_PIN 3 //Connect a button to this PIN. If the button is hold, an the device is turned on the default ethernet settings are restored. /* structure which is stored in the eeprom. * Look at "EEPROMAnything.h" for the functions storing and reading the struct @@ -123,14 +126,14 @@ void set_EEPROM_Default() { // set the default IP address for the arduino. In this case its 192.168.0.111 eeprom_config.ip[0]=192; eeprom_config.ip[1]=168; - eeprom_config.ip[2]=0; - eeprom_config.ip[3]=111; + eeprom_config.ip[2]=1; + eeprom_config.ip[3]=39; // set the default GATEWAY. In this case its 192.168.0.254 eeprom_config.gateway[0]=192; eeprom_config.gateway[1]=168; - eeprom_config.gateway[2]=0; - eeprom_config.gateway[3]=254; + eeprom_config.gateway[2]=1; + eeprom_config.gateway[3]=1; // set the default SUBNET. In this case its 255.255.255.0 eeprom_config.subnet[0]=255; @@ -141,8 +144,8 @@ void set_EEPROM_Default() { // set the default DNS SERVER. In this case its 192.168.0.254 eeprom_config.dns_server[0]=192; eeprom_config.dns_server[1]=168; - eeprom_config.dns_server[2]=0; - eeprom_config.dns_server[3]=254; + eeprom_config.dns_server[2]=1; + eeprom_config.dns_server[3]=1; // set the default Webserver Port. In this case its Port 80 eeprom_config.webserverPort=80; @@ -685,9 +688,9 @@ void setupNetHTML(WebServer &server, WebServer::ConnectionType type, char *url_t server.printP(table_tr_start); server.printP(table_td_start); - server.printP(RAM_1); - server.print(sys.ramFree()); - server.printP(RAM_2); + //server.printP(RAM_1); + // server.print(sys.ramFree()); + // server.printP(RAM_2); server.print(sys.ramSize()); server.printP(table_td_end); server.printP(table_tr_end); @@ -761,6 +764,8 @@ void setup() /* start the webserver */ webserver->begin(); + // Serial.print("Web server is at "); + // Serial.println(Ethernet.localIP()); } /** diff --git a/examples/Web_Parms/Web_Parms.ino b/examples/Web_Parms/Web_Parms.ino deleted file mode 100644 index 504bc81..0000000 --- a/examples/Web_Parms/Web_Parms.ino +++ /dev/null @@ -1,285 +0,0 @@ -/* Web_Parms_1.pde - very simple Webduino example of parameter passing and parsing */ - -/* - * This is mostly a tool for testing and debugging the library, but can - * also be used as an example of coding for it. - * - * To use it, enter one of the following USLs into your browser. - * Replace "host" with the IP address assigned to the Arduino. - * - * http://host/ - * http://host/index.html - * - * These return a "success" HTTP result and display the parameters - * (if any) passed to them as a single string, without attempting to - * parse them. This is done with a call to defaultCmd. - * - * - * http://host/raw.html - * - * This is essentially the same as the index.html URL processing, - * but is done by calling rawCmd. - * - * - * http://host/parsed.html - * - * This invokes parsedCmd, which displays the "raw" parameter string, - * but also uses the "nexyURLparam" routine to parse out the individual - * parameters, and display them. - */ - - -#define WEBDUINO_FAIL_MESSAGE "

Request Failed

" -#include "SPI.h" // new include -#include "avr/pgmspace.h" // new include -#include "Ethernet.h" -#include "WebServer.h" - -#define VERSION_STRING "0.1" - -/* CHANGE THIS TO YOUR OWN UNIQUE VALUE. The MAC number should be - * different from any other devices on your network or you'll have - * problems receiving packets. */ -static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; - - -/* CHANGE THIS TO MATCH YOUR HOST NETWORK. Most home networks are in - * the 192.168.0.XXX or 192.168.1.XXX subrange. Pick an address - * that's not in use and isn't going to be automatically allocated by - * DHCP from your router. */ -static uint8_t ip[] = { 192, 168, 1, 210 }; - -// ROM-based messages used by the application -// These are needed to avoid having the strings use up our limited -// amount of RAM. - -P(Page_start) = "Web_Parms_1 Version " VERSION_STRING "\n"; -P(Page_end) = ""; -P(Get_head) = "

GET from "; -P(Post_head) = "

POST to "; -P(Unknown_head) = "

UNKNOWN request for "; -P(Default_head) = "unidentified URL requested.


\n"; -P(Raw_head) = "raw.html requested.
\n"; -P(Parsed_head) = "parsed.html requested.
\n"; -P(Good_tail_begin) = "URL tail = '"; -P(Bad_tail_begin) = "INCOMPLETE URL tail = '"; -P(Tail_end) = "'
\n"; -P(Parsed_tail_begin) = "URL parameters:
\n"; -P(Parsed_item_separator) = " = '"; -P(Params_end) = "End of parameters
\n"; -P(Post_params_begin) = "Parameters sent by POST:
\n"; -P(Line_break) = "
\n"; - - - -/* This creates an instance of the webserver. By specifying a prefix - * of "", all pages will be at the root of the server. */ -#define PREFIX "" -WebServer webserver(PREFIX, 80); - - - -/* commands are functions that get called by the webserver framework - * they can read any posted data from client, and they output to the - * server to send data back to the web browser. */ -void helloCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) -{ - /* this line sends the standard "we're all OK" headers back to the - browser */ - server.httpSuccess(); - - /* if we're handling a GET or POST, we can output our data here. - For a HEAD request, we just stop after outputting headers. */ - if (type == WebServer::HEAD) - return; - - server.printP(Page_start); - switch (type) - { - case WebServer::GET: - server.printP(Get_head); - break; - case WebServer::POST: - server.printP(Post_head); - break; - default: - server.printP(Unknown_head); - } - - server.printP(Default_head); - server.printP(tail_complete ? Good_tail_begin : Bad_tail_begin); - server.print(url_tail); - server.printP(Tail_end); - server.printP(Page_end); - -} - - -void rawCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) -{ - /* this line sends the standard "we're all OK" headers back to the - browser */ - server.httpSuccess(); - - /* if we're handling a GET or POST, we can output our data here. - For a HEAD request, we just stop after outputting headers. */ - if (type == WebServer::HEAD) - return; - - server.printP(Page_start); - switch (type) - { - case WebServer::GET: - server.printP(Get_head); - break; - case WebServer::POST: - server.printP(Post_head); - break; - default: - server.printP(Unknown_head); - } - - server.printP(Raw_head); - server.printP(tail_complete ? Good_tail_begin : Bad_tail_begin); - server.print(url_tail); - server.printP(Tail_end); - server.printP(Page_end); - -} - -#define NAMELEN 32 -#define VALUELEN 32 - -void parsedCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) -{ - URLPARAM_RESULT rc; - char name[NAMELEN]; - char value[VALUELEN]; - - /* this line sends the standard "we're all OK" headers back to the - browser */ - server.httpSuccess(); - - /* if we're handling a GET or POST, we can output our data here. - For a HEAD request, we just stop after outputting headers. */ - if (type == WebServer::HEAD) - return; - - server.printP(Page_start); - switch (type) - { - case WebServer::GET: - server.printP(Get_head); - break; - case WebServer::POST: - server.printP(Post_head); - break; - default: - server.printP(Unknown_head); - } - - server.printP(Parsed_head); - server.printP(tail_complete ? Good_tail_begin : Bad_tail_begin); - server.print(url_tail); - server.printP(Tail_end); - - if (strlen(url_tail)) - { - server.printP(Parsed_tail_begin); - while (strlen(url_tail)) - { - rc = server.nextURLparam(&url_tail, name, NAMELEN, value, VALUELEN); - if (rc == URLPARAM_EOS) - server.printP(Params_end); - else - { - server.print(name); - server.printP(Parsed_item_separator); - server.print(value); - server.printP(Tail_end); - } - } - } - if (type == WebServer::POST) - { - server.printP(Post_params_begin); - while (server.readPOSTparam(name, NAMELEN, value, VALUELEN)) - { - server.print(name); - server.printP(Parsed_item_separator); - server.print(value); - server.printP(Tail_end); - } - } - server.printP(Page_end); - -} - -void my_failCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) -{ - /* this line sends the "HTTP 400 - Bad Request" headers back to the - browser */ - server.httpFail(); - - /* if we're handling a GET or POST, we can output our data here. - For a HEAD request, we just stop after outputting headers. */ - if (type == WebServer::HEAD) - return; - - server.printP(Page_start); - switch (type) - { - case WebServer::GET: - server.printP(Get_head); - break; - case WebServer::POST: - server.printP(Post_head); - break; - default: - server.printP(Unknown_head); - } - - server.printP(Default_head); - server.printP(tail_complete ? Good_tail_begin : Bad_tail_begin); - server.print(url_tail); - server.printP(Tail_end); - server.printP(Page_end); - -} - - - - -void setup() -{ - /* initialize the Ethernet adapter */ - Ethernet.begin(mac, ip); - - /* setup our default command that will be run when the user accesses - * the root page on the server */ - webserver.setDefaultCommand(&helloCmd); - - /* setup our default command that will be run when the user accesses - * a page NOT on the server */ - webserver.setFailureCommand(&my_failCmd); - - /* run the same command if you try to load /index.html, a common - * default page name */ - webserver.addCommand("index.html", &helloCmd); - - /*This command is called if you try to load /raw.html */ - webserver.addCommand("raw.html", &rawCmd); - webserver.addCommand("parsed.html", &parsedCmd); - - /* start the webserver */ - webserver.begin(); -} - -void loop() -{ - char buff[64]; - int len = 64; - - /* process incoming connections one at a time forever */ - webserver.processConnection(buff, &len); -} diff --git a/readme.md b/readme.md index e312bc1..b858020 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,11 @@ This is an Arduino-based Web Server library, originally developed for a class at NYC Resistor. It's called Webduino, and it's an extensible web server library for the Arduino using the Wiznet-based Ethernet shields. It's released under the MIT license allowing all sorts of reuse. +Modify for +[NUCLEO-F429ZI](http://www.st.com/en/evaluation-tools/nucleo-f429zi.html) +with [STM32duino](https://github.com/stm32duino) + + ## Features - URL parameter parsing