LeeT WiFiLamp code and test
Dependencies: ESP8266_WebServer mbed
Fork of WiFiLamp by
Revision 26:ea5e0ff46492, committed 2015-01-07
- Comitter:
- leet
- Date:
- Wed Jan 07 21:36:45 2015 +0000
- Parent:
- 25:841fc9daffa5
- Commit message:
- Add favicon, robots.txt and LED Disco Function, no WebGUI yet.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
resource.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 841fc9daffa5 -r ea5e0ff46492 main.cpp --- a/main.cpp Tue Jan 06 18:44:43 2015 +0000 +++ b/main.cpp Wed Jan 07 21:36:45 2015 +0000 @@ -52,6 +52,34 @@ ledStrip.write(colors, LED_COUNT); } +void setDiscoColor( ) +{ + for ( int c = 0; c < LED_COUNT; c++ ) + { + colors[c].red = rand()%255; + colors[c].green = rand()%255; + colors[c].blue = rand()%255; + } + + ledStrip.write(colors, LED_COUNT); +} + +Timer DiscoTimer; +#define DiscoDelay 100 + +int lampMode = 0; + +unsigned long heapSize() +{ + char stackVariable; + void *heap; + unsigned long result; + heap = malloc(4); + result = (uint8_t*)&stackVariable - (uint8_t*)heap; + free(heap); + return result; +} + void sendConfigJSONReply(int linkID, const char* result) { sprintf(temp, jsonConfigReply, opMode, stationIP.c_str(), ssid.c_str(), result); server.SendReply(linkID, temp, mimeJSON, 0); @@ -63,7 +91,7 @@ pc.attach(&pcrxint); #endif - pc.printf("WiFi Lamp - %s...\r\n", VERSION); + pc.printf("\r\nWiFi Lamp - %s...\r\n", VERSION); setColor( 25, 0, 0); @@ -73,6 +101,7 @@ wifiSerial.attach(&rxint); #ifdef DEBUG_WIFI server.debugSerial = &pc; + pc.printf("Debug WiFi Enabled!\r\n"); #endif wait_ms(1000); @@ -84,7 +113,6 @@ server.ResetModule(); wifiOn = 1; - std::string fwVer = server.GetFirmwareVersion(); pc.printf("ESP Firmware Version: %s\r\n", fwVer.c_str()); @@ -112,6 +140,9 @@ wait_ms(500); setColor( 0, 0, 0); + pc.printf("Heap Memory %d", heapSize()); + DiscoTimer.start(); + std::string httpReply; while(true) { ESP8266_WebRequest* request = server.GetRequest(); @@ -120,7 +151,7 @@ for( std::map<std::string,std::string>::iterator it = request->Parameters.begin(); it!=request->Parameters.end(); ++it ) { pc.printf("HTTP Parameter %s = %s\r\n", it->first.c_str(), it->second.c_str()); } - if( request->URI == "/" ) { + if( request->URI == "/" || request->URI == "/index.html" ) { httpReply = htmlHead; httpReply += "<table><tr><td align='right'><a href='config'><img src='config.gif' /></a></td></tr>"; httpReply += "<tr><td align='center'>"; @@ -185,11 +216,21 @@ } else if( request->URI == "/wifilamp.css" ) { server.SendReply(request->LinkID, css, strlen(css), mimeCSS); } else if( request->URI == "/colormap.gif" ) { - server.SendReply(request->LinkID, (char*)colormap, sizeof(colormap), mimeGIF); + server.SendReply(request->LinkID, (char*)colorMap, sizeof(colorMap), mimeGIF); } else if( request->URI == "/config.gif" ) { server.SendReply(request->LinkID, (char*)configIcon, sizeof(configIcon), mimeGIF); + } else if( request->URI == "/robtos.txt" ) { + server.SendReply(request->LinkID, robotsTxt, strlen(robotsTxt), mimeText); + } else if( request->URI == "/favicon.ico" ) { + server.SendReply(request->LinkID, (char*)favIcon, sizeof(favIcon), "image/x-icon"); + } else if( request->URI == "/disco" ) { + lampMode = 2; // All colours + DiscoTimer.reset(); + server.SendReply(request->LinkID, "OK", mimeText, 0); } else if( request->URI == "/setcolour" || request->URI == "/setcolor" ) { int r=0, g=0, b=0; + + lampMode = 1; // All LED 1 colour if(request->Parameters.count("r") > 0) r=atoi(request->Parameters["r"].c_str()); if(request->Parameters.count("g") > 0) g=atoi(request->Parameters["g"].c_str()); @@ -206,5 +247,20 @@ pc.printf("\r\nHTTP Reply Sent\r\n"); delete request; } + if( lampMode == 2 && DiscoTimer.read_ms() > DiscoDelay ) { + setDiscoColor(); + // Delay random colour change, else it just looks white + DiscoTimer.reset(); + } +/* + if( lampMode == 3 ) { + // strobe + } + + if( lampMode == 4 ) { + // fade + } + +*/ } } \ No newline at end of file
diff -r 841fc9daffa5 -r ea5e0ff46492 resource.h --- a/resource.h Tue Jan 06 18:44:43 2015 +0000 +++ b/resource.h Wed Jan 07 21:36:45 2015 +0000 @@ -35,7 +35,9 @@ padding: 4px 10px;} table#config tr td input[type=button] {padding: 5px 20px;margin-top: 10px;} div#message {text-align: center;font-size: x-large;padding-bottom: 10px;}"; const char areaHTML[] = "<area shape='poly' coords='%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d'>"; -const char htmlHead[] = "<html><head><title>RGB WiFi Lamp</title><link rel='stylesheet' href='wifilamp.css' /><script src='wifilamp.js'></script></head><body onLoad='onLoad()'>"; +const char htmlHead[] = "<html><head><title>RGB WiFi Lamp</title><link rel='shortcut icon' href='/favicon.ico' type='image/x-icon'>\ +<link rel='icon' href='/favicon.ico' type='image/x-icon'><link rel='stylesheet' href='/wifilamp.css' /><script src='/wifilamp.js'>\ +</script></head><body onLoad='onLoad()'>"; const char htmlTail[] = "</body></html>"; const char htmlConfigHTML[] = "<div id='message'></div><table id='config'>\ @@ -57,7 +59,7 @@ </table>"; const char jsonConfigReply[] = "{\"opmode\":%d,\"staip\":\"%s\",\"ssid\":\"%s\",\"result\":\"%s\"}"; -const unsigned char colormap[7074]= +const unsigned char colorMap[7074]= { 0x47,0x49,0x46,0x38,0x39,0x61,0xEA,0x00,0xC7,0x00,0xE6, 0x7F,0x00,0x99,0x00,0x00,0x00,0xCC,0xFF,0x33,0x33,0x00, @@ -705,7 +707,7 @@ 0x3B, }; -unsigned char configIcon[144]= +const unsigned char configIcon[144]= { 0x47,0x49,0x46,0x38,0x39,0x61,0x10,0x00,0x10,0x00,0xA2, 0x06,0x00,0xC0,0xC0,0xC0,0x80,0x80,0x00,0x80,0x80,0x80, @@ -722,3 +724,82 @@ 0x78,0x4A,0xF5,0x00,0x85,0x17,0x07,0xCC,0x91,0x00,0x00, 0x3B, }; + +const char robotsTxt[] = "User-agent: *\r\n\ +Disallow: /\r\n"; + +// http://favicon-generator.org/about/ +// hexdump -e '15/1 "0x%02X, " 1/1 " 0x%02X,\n"' favicon.ico >> resources.h +const unsigned char favIcon[1150] = +{ + 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x10, 0x10, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x68, 0x04, + 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x12, 0x0B, + 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x88, + 0xB7, 0x00, 0xCD, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x00, 0xCC, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xCD, 0x00, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x00, 0xBC, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x00, + 0x33, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x90, 0x88, + 0xB7, 0x00, 0xFF, 0x00, 0xBC, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x00, + 0xCC, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x90, 0x88, + 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0xFF, 0x09, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x90, 0x88, + 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0xEF, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x90, 0x88, + 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x09, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x00, 0xF7, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x00, 0xBC, 0xFF, 0x00, 0x80, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x09, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x00, 0xBC, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0x00, 0xF7, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0xEF, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x90, 0x88, + 0xB7, 0x00, 0xFF, 0x00, 0xBC, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xCD, 0x00, 0xFF, 0xFF, 0x00, 0x00, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x00, 0xF7, + 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0x09, 0xFF, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xEF, 0xFF, + 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x09, 0x00, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xFF, 0x00, + 0xBC, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xCD, 0x00, 0xFF, 0xFF, 0x90, 0x88, 0xB7, 0x00, 0xAA, 0xAA, + 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0xAA, 0xAA, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0xAA, 0xAA, +}; +