Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos Watchdog SW_HTTPServer SW_String EthernetInterface TimeInterface SSDP
Diff: WebPages.cpp
- Revision:
- 1:016d4400254b
- Parent:
- 0:de1dfa2ab813
- Child:
- 2:ca5d12560ff7
--- a/WebPages.cpp Tue Jul 03 02:10:23 2018 +0000
+++ b/WebPages.cpp Tue Jul 03 16:26:21 2018 +0000
@@ -24,7 +24,7 @@
// sprintf(buf, ROOTPAGE, "NodeName", "NodeName", "BuildDate",
-static const char * ROOTPAGE =
+static const char ROOTPAGE[] =
"<!DOCTYPE html>\r\n"
"<html><head><title>%s</title>\r\n"
"</head>\r\n"
@@ -33,10 +33,26 @@
"This project demonstrates the Smartware web server and the Smartware SSDP discovery server.\n"
"You should be able to scan the network (e.g. in Windows Explorer) and find this device.\n"
"Then you can click on it to open this web page to interact with it.\n"
- "<br/><br/>\n"
+ "<br/><br/>Build %s<br/><br/>\n"
+ "<font size='+5'>\n"
+ "<table><tr>\n"
+ "<td>"
+ "<button onclick=\"window.location.href='/?LED=1&CMD=1'\">LED 1 On</button><br/>\n"
+ "<button onclick=\"window.location.href='/?LED=1&CMD=0'\">LED 1 Off</button><br/>\n"
+ "</td><td>"
+ "<button onclick=\"window.location.href='/?LED=2&CMD=1'\">LED 2 On</button><br/>\n"
+ "<button onclick=\"window.location.href='/?LED=2&CMD=0'\">LED 2 Off</button><br/>\n"
+ "</td><td>"
+ "<button onclick=\"window.location.href='/?LED=3&CMD=1'\">LED 3 On</button><br/>\n"
+ "<button onclick=\"window.location.href='/?LED=3&CMD=0'\">LED 3 Off</button><br/>\n"
+ "</td><td>"
+ "<button onclick=\"window.location.href='/?LED=4&CMD=1'\">LED 4 On</button><br/>\n"
+ "<button onclick=\"window.location.href='/?LED=4&CMD=0'\">LED 4 Off</button><br/>\n"
+ "</td>"
+ "</tr></table>\n"
+ "</font>\n"
"<form method='get'>\n"
"<table>\n"
- "<tr><td>Build</td><td>%s</td></tr>\n"
"<tr><td>Set LED</td>\n"
"<td><select name='LED'>\n"
" <option value='1'>1</option>\n"
@@ -200,9 +216,14 @@
HTTPServer::CallBackResults RootPage(HTTPServer *svr, HTTPServer::CallBackType type, char * path,
const HTTPServer::namevalue *queryParams, int queryParamCount)
{
- char BigBuffer[1000];
+ #define bufSize (sizeof(ROOTPAGE) + 100)
+ char * BigBuffer = (char *)malloc(bufSize);
HTTPServer::CallBackResults ret = HTTPServer::ACCEPT_ERROR;
printf("RootPage responder\n");
+ if (!BigBuffer) {
+ printf("cannot allocate %d bytes\n", bufSize);
+ return ret;
+ }
int led, cmd;
int mask = 0;
@@ -231,7 +252,7 @@
switch (type) {
case HTTPServer::SEND_PAGE:
svr->header(HTTPServer::OK, "OK", hdrTypeHTML_NoCache);
- sprintf(BigBuffer, ROOTPAGE, PROG_NAME, PROG_NAME, BUILD_DATE);
+ snprintf(BigBuffer, bufSize, ROOTPAGE, PROG_NAME, PROG_NAME, BUILD_DATE);
svr->send(BigBuffer);
ret = HTTPServer::ACCEPT_COMPLETE;
break;
@@ -245,5 +266,7 @@
ret = HTTPServer::ACCEPT_ERROR;
break;
}
+ if (BigBuffer)
+ free(BigBuffer);
return ret;
}
