LeeT WiFiLamp code and test
Dependencies: ESP8266_WebServer mbed
Fork of WiFiLamp by
Diff: main.cpp
- Revision:
- 20:f5a6527bfda6
- Parent:
- 19:7fdccfd5b50b
- Child:
- 22:6d7a72fab8ff
diff -r 7fdccfd5b50b -r f5a6527bfda6 main.cpp --- a/main.cpp Mon Dec 29 21:00:26 2014 +0000 +++ b/main.cpp Wed Dec 31 15:15:50 2014 +0000 @@ -18,6 +18,16 @@ Serial pc(USBTX,USBRX); ESP8266_WebServer server(&wifiSerial); +const char javascript[] = "function hello() { alert('Hello World'); }"; +const char css[] = "body { background-color:#DDDDDD; font-size:14px; }"; + +#ifdef DEBUG_WIFI +void pcrxint(void) { + server.debugBuffers(&pc); + server.echoMode = true; +} +#endif + void rxint(void) { server.rxint(); } @@ -36,6 +46,9 @@ int main() { pc.baud(115200); +#ifdef DEBUG_WIFI + pc.attach(&pcrxint); +#endif pc.printf("WiFi Lamp - v0.02 ...\r\n"); @@ -74,7 +87,9 @@ } std::string httpReply; if( request->URI == "/" ) { - httpReply = "<html><title>WiFi Lamp</title> \ + httpReply = "<html><head><title>WiFi Lamp</title> \ +<link rel='stylesheet' href='wifilamp.css'> \ +<script src='wifilamp.js'></script></head> \ <body><h1>The WiFi Lamp v0.02 is alive ...</h1>Quick colour links:<br> \ <a href='/red'>Red</a><br><a href='/green'>Green</a><br><a href='/blue'>Blue</a><br><a href='/white'>White</a><br> \ <form id='setcolour' action='setcolour' > \ @@ -94,6 +109,10 @@ </body></html>"; setColor(0,0,0); server.SendReply(request->LinkID, httpReply, mimeHTML); + } else if( request->URI == "/wifilamp.js" ) { + server.SendReply(request->LinkID, javascript, strlen(javascript), mimeJavaScript); + } else if( request->URI == "/wifilamp.css" ) { + server.SendReply(request->LinkID, css, strlen(css), mimeCSS); } else if( request->URI == "/red" ) { httpReply = "<html><head><title>WiFi Lamp</title></head><body><h1>The WiFi Lamp is now Red - To Turn <a href='/'>Off</a></h1></body></html>"; setColor(100, 0, 0); @@ -129,7 +148,5 @@ pc.printf("\r\nHTTP Reply Sent\r\n"); delete request; } - - wait_ms(10); } } \ No newline at end of file