LeeT WiFiLamp code and test
Dependencies: ESP8266_WebServer mbed
Fork of WiFiLamp by
Diff: main.cpp
- Revision:
- 11:3ab606a42227
- Parent:
- 9:319aeb6e0123
- Child:
- 12:fbf950985e1c
--- a/main.cpp Sat Dec 27 05:56:47 2014 +0000 +++ b/main.cpp Sun Dec 28 16:04:22 2014 +0000 @@ -18,6 +18,9 @@ Serial pc(USBTX,USBRX); ESP8266_WebServer server(&wifiSerial); +const char javascript[] = "function test() { alert('Hello'); }"; +const char css[] = "body { background: #DDDDDD; }"; + void rxint(void) { server.rxint(); } @@ -72,13 +75,18 @@ } std::string httpReply; if( request->URI == "/" ) { - httpReply = "<html><head><title>WiFi Lamp</title></head><body><h1>The WiFi Lamp is alive(<a href='/red'>Red</a>)</h1></body></html>"; - setColor(0,0,0); - server.SendHTMLReply(request->LinkID, httpReply); - } else if( request->URI == "/red" ) { - httpReply = "<html><head><title>WiFi Lamp</title></head><body><h1>The WiFi Lamp(Red) is alive(<a href='/'>Off</a>)</h1></body></html>"; - setColor(100, 0, 0); - server.SendHTMLReply(request->LinkID, httpReply); + httpReply = "<html><head>"; + httpReply += "<title>WiFi Lamp</title>"; + httpReply += "<link rel='stylesheet' type='text/css' href='wifilamp.css'>"; + httpReply += "<script type='text/javascript' src='wifilamp.js'></script>"; + httpReply += "</head><body>"; + httpReply += "<h1>The WiFi Lamp is alive(<a href='/red'>Red</a>)</h1>"; + httpReply += "</body></html>"; + server.SendReply(request->LinkID, httpReply, mimeHTML); + } else if( request->URI == "/wifilamp.js" ) { + server.SendReply(request->LinkID, javascript, sizeof(javascript), mimeJavaScript); + } else if( request->URI == "/wifilamp.css" ) { + server.SendReply(request->LinkID, css, sizeof(css), mimeCSS); } else if ( request->URI == "/setcolor" ) { int r=0, g=0, b=0; @@ -91,9 +99,9 @@ setColor( r,g,b ); httpReply = "<html><head><title>WiFi Lamp</title></head><body>ok</body></html>"; - server.SendHTMLReply(request->LinkID, httpReply); + server.SendReply(request->LinkID, httpReply, mimeHTML); } else { - server.Send404Reply(request->LinkID); + server.Send404Error(request->LinkID); } pc.printf("\r\nHTTP Reply Sent\r\n"); delete request;