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
Fork of webserverBlinky by
Revision 193:8d3c9e94a4fb, committed 2017-11-20
- Comitter:
- plebs96
- Date:
- Mon Nov 20 22:03:28 2017 +0000
- Parent:
- 192:73fdbdc479dd
- Commit message:
- webserverBlinky
Changed in this revision
--- a/PPP-Blinky/ppp-blinky.cpp Sat Nov 11 10:32:20 2017 +0000
+++ b/PPP-Blinky/ppp-blinky.cpp Mon Nov 20 22:03:28 2017 +0000
@@ -57,7 +57,7 @@
#error The LPC11U24 does not have a second serial port to use for debugging - change SERIAL_PORT_MONITOR_YES back to SERIAL_PORT_MONITOR_NO
#elif defined (TARGET_KL46Z) || (TARGET_KL25Z)
RawSerial xx(PTE0,PTE1); // Second serial port on FRDM-KL46Z board
-#elif defined(YOUR_TARGET_BOARD_NAME_HERE)
+#elif defined(TARGET_KW41Z)
// change the next line to YOUR target board's second serial port pin definition if it's not present - and if it works, please send it to me - thanks!!!
RawSerial xx(p9, p10); // change this to YOUR board second serial port pin definition - and please send it to me if it works!!!
#else
@@ -82,28 +82,30 @@
// this is the webpage we serve when we get an HTTP request to root (/)
// keep size under ~900 bytes to fit into a single PPP packet
-
-const static char rootWebPage[] = "\
-<!DOCTYPE html>\
-<html>\
-<head>\
-<title>mbed PPP-Blinky</title>\r\n\
-<script>\r\n\
-window.onload=function(){\
-setInterval(function(){function x(){return document.getElementById('w');};\
-x().textContent=parseInt(x().textContent)+1;},100);};\r\n\
-</script>\r\n\
-</head>\
-<body style=\"font-family: sans-serif; font-size:20px; text-align:center; color:#807070\">\
-<h1>mbed PPP-Blinky Up and Running</h1>\
-<h1 id=\"w\">0</h1>\
-<h1><a href=\"http://bit.ly/pppBlink2\">Source on mbed</a></h1>\
-<h1><a href=\"/ws\">WebSocket Demo</a></h1>\
-<h1><a href=\"/x\">Benchmark 1</a></h1>\
-<h1><a href=\"/xb\">Benchmark 2</a></h1>\
-<h1><a href=\"http://jsfiddle.net/d26cyuh2/\">JSFiddle Demo</a></h1>\
-</body>\
-</html>\r\n"; // size = 644 bytes plus 1 null byte = 645 bytes
+char body[] = \
+ "<html>\
+ <head><title>A simple Web Server</title></head>\
+ <body>\
+ <h1>COMP3215</h1>\
+ <form action=\"\" method=\"post\">\
+ <button name=\"button\" value='1' disable=\"disable\">LED ON</button>\
+ <button name=\"button\" value='0' disable=\"disable\">LED OFF</button>\
+ </form>\
+ </body>\
+ </html>";
+//const static char rootWebPage[] = "\
+//<!DOCTYPE html>
+//<html>\
+//<head><title>A simple Web Server</title></head>\
+//<body>\
+//<h1>COMP3215</h1>\
+//<form action=\"\" method=\"post\">\
+//<button name=\"button\" value='1' disable=\"disable\">LED ON</button>\
+//<button name=\"button\" value='0' disable=\"disable\">LED OFF</button>\
+//</form>\
+//</body>\
+//</html>";
+ // size = 644 bytes plus 1 null byte = 645 bytes
// this is a websocket demo html page we serve when GET /ws is requested
const static char webSocketPage[] = "\
@@ -150,7 +152,7 @@
// On a typical mbed hardware platform this serial port is a USB virtual com port (VCP) and the USB serial driver is supplied by the board vendor.
RawSerial pc (USBTX, USBRX); // usb virtual com port for mbed hardware
-DigitalOut led1(LED1); // this led toggles when a packet is received
+ DigitalOut led1(LED1);// this led toggles when a packet is received
// the standard hdlc frame start/end character. It's the tilde character "~"
#define FRAME_7E (0x7e)
@@ -186,6 +188,9 @@
/// Returns 1 after a connect message, 0 at startup or after a disconnect message
int connectedPpp()
{
+// cnt = 0;
+// if(cnt == 0)
+// led_flash();
return ppp.online;
}
@@ -877,19 +882,24 @@
int nHeader; // byte size of HTTP header
int contentLengthStart; // index where HTML starts
- int httpGet5,httpGet6,httpGetx, httpGetRoot; // temporary storage of strncmp results
+ int httpGet5,httpGet6,httpGetx, httpGetRoot;
+ int httpGetLedOff,httpGetLedOn; // temporary storage of strncmp results
*flags = TCP_FLAG_ACK | TCP_FLAG_FIN; // the default case is that we close the connection
httpGetRoot = strncmp(dataStart, "GET / HTTP/1.", 13); // found a GET to the root directory
httpGetx = strncmp(dataStart, "GET /x", 6); // found a GET to /x which we will treat special (anything starting with /x, e.g. /x, /xyz, /xABC?pqr=123
httpGet5 = dataStart[5]; // the first character in the path name, we use it for special functions later on
httpGet6 = dataStart[6]; // the second character in the path name, we use it for special functions later on
+ httpGetLedOff = strncmp(dataStart,"button=0",9);
+ httpGetLedOn = strncmp(dataStart,"button=1",9);
+
// for example, you could try this using netcat (nc): echo "GET /x" | nc 172.10.10.2
if( (httpGetRoot==0) || (httpGetx==0) ) {
n=n+sprintf(n+dataStart,"HTTP/1.1 200 OK\r\nServer: mbed-PPP-Blinky-v1\r\n"); // 200 OK header
} else {
n=n+sprintf(n+dataStart,"HTTP/1.1 404 Not Found\r\nServer: mbed-PPP-Blinky\r\n"); // 404 header
}
+
n=n+sprintf(n+dataStart,"Content-Length: "); // http header
contentLengthStart = n; // remember where Content-Length is in buffer
n=n+sprintf(n+dataStart,"?????\r\n"); // leave five spaces for content length - will be updated later
@@ -899,14 +909,17 @@
if( httpGetRoot == 0 ) {
// this is where we insert our web page into the buffer
- memcpy(n+dataStart,rootWebPage,sizeof(rootWebPage));
- n = n + sizeof(rootWebPage)-1; // one less than sizeof because we don't count the null byte at the end
+ memcpy(n+dataStart,body,sizeof(body));
+ n = n + sizeof(body)-1; // one less than sizeof because we don't count the null byte at the end
} else if ( (httpGet5 == 'w') && (httpGet6 == 's') ) { // "ws" is a special page for websocket demo
- memcpy(n+dataStart,webSocketPage,sizeof(webSocketPage));
- n = n + sizeof(webSocketPage)-1; // one less than size
+ memcpy(n+dataStart,body,sizeof(body));
+ n = n + sizeof(body)-1; // one less than size
*flags = TCP_FLAG_ACK | TCP_FLAG_PSH; // for a websocket page we do NOT close the connection
- } else {
+ led1=!led1;
+ }
+
+ else {
if (httpGetx == 0) { // the page request started with "GET /x" - here we treat anything starting with /x special:
#define W3C_COMPLIANT_RESPONSE_NO
// change the above to W3C_COMPLIANT_RESPONSE_YES if you want a W3C.org compliant HTTP response
@@ -926,6 +939,16 @@
n=n+sprintf(n+dataStart,"<body>Not Found</body>"); // not found message
}
}
+ //add
+ if(httpGetLedOn !=0)
+ {
+ led1 = 1;
+ }
+
+ if(httpGetLedOff !=0)
+ {
+ led1 = 0;
+ }
#define CONTENTLENGTHSIZE 5
char contentLengthString[CONTENTLENGTHSIZE+1];
snprintf(contentLengthString,CONTENTLENGTHSIZE+1,"%*d",CONTENTLENGTHSIZE,n-nHeader); // print Content-Length with leading spaces and fixed width equal to csize
@@ -1265,6 +1288,14 @@
/// Initialize PPP data structure and set serial port(s) baud rate(s)
void initializePpp()
{
+ int i = 0;
+ while(1)
+ {
+ debugPrintf("1111111111111\n");
+ i ++;
+ if(i==010000)
+ break;
+ }
debugBaudRate(115200); // baud rate for (optional) debug serial port
debugPrintf("\x1b[2J\x1b[H\x1b[30m");
wait_ms(200); // a brief wait so a human can see the reset event
@@ -1274,3 +1305,36 @@
pc.baud(115200); // pc serial port acting as a dial-up modem - for PPP traffic
pc.attach(&pppReceiveHandler, RawSerial::RxIrq); // set up serial port receive interrupt handler
}
+
+
+void t_print(int i, char* process)
+{
+
+ while(1)
+ {
+ printf("%s\n", *process);
+ i++;
+ led1=!led1;
+ wait(0.5);
+ if(i==i*3)
+ break;
+ }
+}
+void l_off(void)
+{
+ led1 = 0;
+}
+
+void l_on(void)
+{
+ led1 = 1;
+}
+void led_flash(void)
+{
+ int num = 0;
+ for(num = 0; num < 20; num ++)
+ {
+ led1= !led1;
+ wait(1);
+ }
+}
\ No newline at end of file
--- a/PPP-Blinky/ppp-blinky.h Sat Nov 11 10:32:20 2017 +0000
+++ b/PPP-Blinky/ppp-blinky.h Mon Nov 20 22:03:28 2017 +0000
@@ -170,3 +170,6 @@
} ipData; // ip related object
} pppVariables;
+void t_print(int i, char* process);
+void l_off(void);void l_on(void);
+void led_flash(void);
\ No newline at end of file
--- a/main.cpp Sat Nov 11 10:32:20 2017 +0000
+++ b/main.cpp Mon Nov 20 22:03:28 2017 +0000
@@ -6,11 +6,16 @@
int main()
{
+// int i =1;
initializePpp(); // initialize the serial port(s) and structures
+// l_on();
while(1) {
- waitForPcConnectString(); // wait for PC to send a connect message
+ waitForPcConnectString(); // wait for PC to send a connect message
+// l_off();
while( connectedPpp() ) {
+
waitForPppFrame(); // process PPP frames until we receive a disconnect command
}
+
}
-}
\ No newline at end of file
+}
