From 1d47165831dc3f63a9d82a2126b69e3e9e1e54c2 Mon Sep 17 00:00:00 2001 From: Scott Penrose Date: Wed, 10 Dec 2014 22:14:12 +1100 Subject: [PATCH 1/4] Memory: Add progmem space for Serial Prints. Most of these changes only effect debug mode (Serial.print etc). --- WebServer.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/WebServer.h b/WebServer.h index c8c43c3..3ab4b62 100644 --- a/WebServer.h +++ b/WebServer.h @@ -587,15 +587,15 @@ void WebServer::processConnection(char *buff, int *bufflen) buff[0] = 0; ConnectionType requestType = INVALID; #if WEBDUINO_SERIAL_DEBUGGING > 1 - Serial.println("*** checking request ***"); + Serial.println(F("*** checking request ***")); #endif getRequest(requestType, buff, bufflen); #if WEBDUINO_SERIAL_DEBUGGING > 1 - Serial.print("*** requestType = "); + Serial.print(F("*** requestType = ")); Serial.print((int)requestType); - Serial.print(", request = \""); + Serial.print(F(", request = \"")); Serial.print(buff); - Serial.println("\" ***"); + Serial.println(F("\") ***"); #endif // don't even look further at invalid requests. @@ -607,7 +607,7 @@ void WebServer::processConnection(char *buff, int *bufflen) { processHeaders(); #if WEBDUINO_SERIAL_DEBUGGING > 1 - Serial.println("*** headers complete ***"); + Serial.println(F("*** headers complete ***")); #endif if (strcmp(buff, "/robots.txt") == 0) @@ -635,7 +635,7 @@ void WebServer::processConnection(char *buff, int *bufflen) flushBuf(); #if WEBDUINO_SERIAL_DEBUGGING > 1 - Serial.println("*** stopping connection ***"); + Serial.println(F("*** stopping connection ***")); #endif reset(); } @@ -686,6 +686,7 @@ void WebServer::noRobots(ConnectionType type) void WebServer::favicon(ConnectionType type) { + // XXX string space? httpSuccess("image/x-icon","Cache-Control: max-age=31536000\r\n"); if (type != HEAD) { @@ -802,7 +803,7 @@ int WebServer::read() if (m_contentLength == 0) { #if WEBDUINO_SERIAL_DEBUGGING > 1 - Serial.println("\n*** End of content, terminating connection"); + Serial.println(F("\n*** End of content, terminating connection")); #endif return -1; } @@ -822,9 +823,9 @@ int WebServer::read() #if WEBDUINO_SERIAL_DEBUGGING if (ch == '\r') - Serial.print(""); + Serial.print(F("")); else if (ch == '\n') - Serial.println(""); + Serial.println(F("")); else Serial.print((char)ch); #endif @@ -837,7 +838,7 @@ int WebServer::read() { // connection timed out, destroy client, return EOF #if WEBDUINO_SERIAL_DEBUGGING - Serial.println("*** Connection timed out"); + Serial.println(F("*** Connection timed out")); #endif reset(); return -1; @@ -847,7 +848,7 @@ int WebServer::read() // connection lost, return EOF #if WEBDUINO_SERIAL_DEBUGGING - Serial.println("*** Connection lost"); + Serial.println(F("*** Connection lost")); #endif return -1; } @@ -1241,9 +1242,9 @@ void WebServer::processHeaders() { readInt(m_contentLength); #if WEBDUINO_SERIAL_DEBUGGING > 1 - Serial.print("\n*** got Content-Length of "); + Serial.print(F("\n*** got Content-Length of ")); Serial.print(m_contentLength); - Serial.print(" ***"); + Serial.print(F(" ***")); #endif continue; } @@ -1252,9 +1253,9 @@ void WebServer::processHeaders() { readHeader(m_authCredentials,51); #if WEBDUINO_SERIAL_DEBUGGING > 1 - Serial.print("\n*** got Authorization: of "); + Serial.print(F("\n*** got Authorization: of ")); Serial.print(m_authCredentials); - Serial.print(" ***"); + Serial.print(F(" ***")); #endif continue; } From 6fb2d438b0991795d07be8ea8c708d2c693971c7 Mon Sep 17 00:00:00 2001 From: Scott Penrose Date: Wed, 10 Dec 2014 22:34:42 +1100 Subject: [PATCH 2/4] Some notes from me --- readme.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/readme.md b/readme.md index e312bc1..e34ac02 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,19 @@ 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. +# Scott's Version + +This is a temporary version - where I can get this going on a LinkIt One then +try and push the changes back upstream. + +For the origianl and working version see - https://github.com/sirleech/Webduino + +TODO: +- Support non Ethernet libraries, e.g. WiFiServer / Client +- Look at providing the Server / Client as paramters in (streams) +- Look at documenting PROGMEM usage, e.g. using inline e.g. client.print(F("..."));- +- Look at standard method of defining AJAX/REST calls + ## Features - URL parameter parsing From 3473e85d45dcddef34bd50f1fa57fef618ffd769 Mon Sep 17 00:00:00 2001 From: Scott Penrose Date: Wed, 10 Dec 2014 22:41:48 +1100 Subject: [PATCH 3/4] Initial support for LWifi --- WebServer.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/WebServer.h b/WebServer.h index 3ab4b62..58f3dd7 100644 --- a/WebServer.h +++ b/WebServer.h @@ -29,9 +29,12 @@ #include #include -#include -#include -#include +// #include +// #include +// #include +#include +#include +#include /******************************************************************** * CONFIGURATION @@ -316,8 +319,8 @@ class WebServer: public Print // Close the current connection and flush ethernet buffers void reset(); private: - EthernetServer m_server; - EthernetClient m_client; + LWiFiServer m_server(80); + LWiFiClient m_client; const char *m_urlPrefix; unsigned char m_pushback[32]; From be34e669cd0662aeebfac230b23d148787177629 Mon Sep 17 00:00:00 2001 From: Scott Penrose Date: Fri, 12 Dec 2014 13:13:59 +1100 Subject: [PATCH 4/4] Play with WWiFi --- WebServer.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/WebServer.h b/WebServer.h index 58f3dd7..cddcb94 100644 --- a/WebServer.h +++ b/WebServer.h @@ -36,6 +36,10 @@ #include #include +#define WIFI_AP "your_ap_ssid" +#define WIFI_PASSWORD "your_password" +#define WIFI_AUTH LWIFI_WEP // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration + /******************************************************************** * CONFIGURATION ********************************************************************/ @@ -385,6 +389,11 @@ P(webServerHeader) = "Server: Webduino/" WEBDUINO_VERSION_STRING CRLF; void WebServer::begin() { m_server.begin(); + // keep retrying until connected to AP + Serial.println("Connecting to AP"); + while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD))) { + delay(1000); + } } void WebServer::setDefaultCommand(Command *cmd)