copy of TCPEchoServer, with changes for a make-shift garage door opener

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPEchoServer by mbed official

Files at this revision

API Documentation at this revision

Comitter:
elevatorguy
Date:
Mon Jan 21 19:53:21 2013 +0000
Parent:
7:e2ffd7edf9c9
Child:
9:4d9da861bdcf
Commit message:
action redirect

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jan 21 07:47:59 2013 +0000
+++ b/main.cpp	Mon Jan 21 19:53:21 2013 +0000
@@ -37,7 +37,7 @@
         char secondpage[] = {"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 248\r\n\r\n<html><head><title>Pressing Button</title></head><body><h4>Garage Door Opener</h4><p>Door should be moving...</p><form action=index.html method=post><input style='border : 1px solid #000000;' value='Open/Close' type='submit' /></form></body></html>"};
         char error[] = {"HTTP/1.1 501 Not Implemented\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 100\r\n\r\n<html><head><title>Error</title></head><body>Sorry, I don't understand your request :(</body></html>"};
         char error404[] = {"HTTP/1.1 404 Not Found\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 147\r\n\r\n<html><head><title>Error 404</title></head><body><h1>Page not found.</h1> <h2>404</h2><br /><p>(this is not a real webserver FYI)</p></body></html>"};
-
+        char pagemoved[] = { "HTTP/1.1 301 Moved Permanently\r\nLocation: /index.html\r\n\r\n"} ;
         //I used this website to get string length
         //http://www.string-functions.com/length.aspx
         
@@ -62,8 +62,8 @@
                 && buffer[6] == 'c' && buffer[7] == 't' && buffer[8] == 'i' && buffer[9] == 'o' && buffer[10] == 'n'
                 && buffer[11] == '.' && buffer[12] == 'h' && buffer[13] == 't' && buffer[14] == 'm') // action.htm
                 {
-                    //backwards compatibility with the first way I did it
-                    client.send_all(firstpage, sizeof(firstpage));
+                    //redirect users automatically if they bookmarked action.htm
+                    client.send_all(pagemoved, sizeof(firstpage));
                     if (n <= 0) break;
                 }
                 else