University of Plymouth - Stages 1, 2 and 3
/
Task671-mbedos-FZ429-TCP-dynamic
Simple TCP/IP Server (dynamic web page)
Diff: main.cpp
- Revision:
- 1:76bd6f78cabc
- Parent:
- 0:65ff7ad381e8
- Child:
- 2:ecf4c78019ab
diff -r 65ff7ad381e8 -r 76bd6f78cabc main.cpp --- a/main.cpp Mon Nov 20 17:31:23 2017 +0000 +++ b/main.cpp Tue Nov 21 14:21:48 2017 +0000 @@ -16,7 +16,7 @@ " <body style=\"display:flex;text-align:center\">" "\r\n" \ " <div style=\"margin:auto\">" "\r\n" \ " <h1>Hello World</h1>" "\r\n" \ -" <p>The POT value is " +" <p>The LDR value is " #define HTTP_MESSAGE_BODY2 "" \ "</p>" "\r\n" \ @@ -33,7 +33,7 @@ #define NETMASK "255.0.0.0" #define GATEWAY "10.0.0.1" -AnalogIn pot(PA_0); +AnalogIn ldr(PA_0); int main() @@ -66,17 +66,24 @@ srv.accept(&clt_sock, &clt_addr); printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); + //Uses a C++ string to make it easier to concatinate string response; - char pot_str[64]; - float u = pot; - sprintf(pot_str, "%5.3f", u ); - printf("POT: %5.3f\n\r", u); + //This is a C string + char ldr_str[64]; + + //Read the LDR value + float u = ldr; + //Convert to a C String + sprintf(ldr_str, "%5.3f", u ); + printf("LDR: %5.3f\n\r", u); + + //Build the C++ string response response = HTTP_MESSAGE_BODY1; - response += pot_str; + response += ldr_str; response += HTTP_MESSAGE_BODY2; - //Send static HTML response + //Send static HTML response (as a C string) clt_sock.send(response.c_str(), response.size()+6); } }