![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
KEIS
Dependencies: C12832_lcd EthernetInterface_t LM75B mbed-rtos mbed
main.cpp@1:16bab08d1c37, 2013-09-28 (annotated)
- Committer:
- khayakawa
- Date:
- Sat Sep 28 16:25:46 2013 +0000
- Revision:
- 1:16bab08d1c37
- Parent:
- 0:b99a49731909
KEIS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
khayakawa | 0:b99a49731909 | 1 | #include "mbed.h" |
khayakawa | 0:b99a49731909 | 2 | #include "rtos.h" |
khayakawa | 0:b99a49731909 | 3 | #include "EthernetInterface.h" |
khayakawa | 0:b99a49731909 | 4 | #include "C12832_lcd.h" |
khayakawa | 0:b99a49731909 | 5 | |
khayakawa | 0:b99a49731909 | 6 | C12832_LCD lcd; |
khayakawa | 0:b99a49731909 | 7 | |
khayakawa | 0:b99a49731909 | 8 | // const char* SERVER_ADDRESS = "192.168.50.121"; |
khayakawa | 0:b99a49731909 | 9 | const int SERVER_PORT = 80; |
khayakawa | 0:b99a49731909 | 10 | |
khayakawa | 0:b99a49731909 | 11 | const char* MY_ADDRESS = "192.168.50.125"; |
khayakawa | 0:b99a49731909 | 12 | const char* MY_MASK = "255.255.255.0"; |
khayakawa | 0:b99a49731909 | 13 | const char* MY_GATEWAY = "192.168.50.254"; |
khayakawa | 0:b99a49731909 | 14 | |
khayakawa | 0:b99a49731909 | 15 | EthernetInterface eth; |
khayakawa | 0:b99a49731909 | 16 | Serial serial1(p9, p10); // tx, rx |
khayakawa | 0:b99a49731909 | 17 | DigitalOut myled(LED1); |
khayakawa | 0:b99a49731909 | 18 | |
khayakawa | 0:b99a49731909 | 19 | |
khayakawa | 0:b99a49731909 | 20 | float a[1]; |
khayakawa | 0:b99a49731909 | 21 | |
khayakawa | 0:b99a49731909 | 22 | |
khayakawa | 0:b99a49731909 | 23 | int main(void) { |
khayakawa | 0:b99a49731909 | 24 | |
khayakawa | 0:b99a49731909 | 25 | a[0]=5; |
khayakawa | 0:b99a49731909 | 26 | |
khayakawa | 0:b99a49731909 | 27 | // set IPAddress , Mask , Gateway |
khayakawa | 0:b99a49731909 | 28 | eth.init(MY_ADDRESS,MY_MASK,MY_GATEWAY); |
khayakawa | 0:b99a49731909 | 29 | eth.connect(); |
khayakawa | 0:b99a49731909 | 30 | printf("IP Address is %s\n", eth.getIPAddress()); |
khayakawa | 0:b99a49731909 | 31 | |
khayakawa | 0:b99a49731909 | 32 | TCPSocketServer server; |
khayakawa | 0:b99a49731909 | 33 | server.bind(SERVER_PORT); |
khayakawa | 0:b99a49731909 | 34 | server.listen(); |
khayakawa | 0:b99a49731909 | 35 | |
khayakawa | 0:b99a49731909 | 36 | while (true) { |
khayakawa | 0:b99a49731909 | 37 | TCPSocketConnection client; |
khayakawa | 0:b99a49731909 | 38 | server.accept(client); |
khayakawa | 0:b99a49731909 | 39 | client.set_blocking(false, 1500); // Timeout after (1.5)s |
khayakawa | 0:b99a49731909 | 40 | |
khayakawa | 0:b99a49731909 | 41 | printf("Connection from: %s\n", client.get_address()); |
khayakawa | 0:b99a49731909 | 42 | char buffer[256]; |
khayakawa | 0:b99a49731909 | 43 | char str[6]; |
khayakawa | 0:b99a49731909 | 44 | char sendbuf[335]; |
khayakawa | 0:b99a49731909 | 45 | sprintf(sendbuf, "HTTP/1.1 200 OK\r\n" |
khayakawa | 0:b99a49731909 | 46 | "Server: 192.168.50.79\r\n" |
khayakawa | 0:b99a49731909 | 47 | "Content-Length: 215\r\n" |
khayakawa | 0:b99a49731909 | 48 | "Content-Type: text/html\r\n" |
khayakawa | 0:b99a49731909 | 49 | "\r\n" |
khayakawa | 0:b99a49731909 | 50 | "<html>\r\n" |
khayakawa | 0:b99a49731909 | 51 | "<head>\r\n" |
khayakawa | 0:b99a49731909 | 52 | "<title>test</title>\r\n" |
khayakawa | 0:b99a49731909 | 53 | "<body>\r\n" |
khayakawa | 0:b99a49731909 | 54 | "<font size=\"7\"><center>Test of tiny server</font></center>\r\n" |
khayakawa | 0:b99a49731909 | 55 | "<center>temperature:%.2f[W]</center>\r\n" |
khayakawa | 0:b99a49731909 | 56 | "</body>\r\n" |
khayakawa | 0:b99a49731909 | 57 | "</html>\r\n" |
khayakawa | 0:b99a49731909 | 58 | , a[0]); |
khayakawa | 0:b99a49731909 | 59 | |
khayakawa | 0:b99a49731909 | 60 | while (true) { |
khayakawa | 0:b99a49731909 | 61 | int n = client.receive(buffer, sizeof(buffer)); |
khayakawa | 0:b99a49731909 | 62 | if (n <= 0) break; |
khayakawa | 0:b99a49731909 | 63 | } |
khayakawa | 0:b99a49731909 | 64 | |
khayakawa | 0:b99a49731909 | 65 | printf("%s\n", buffer); |
khayakawa | 0:b99a49731909 | 66 | strncpy(str, buffer+5, 4); |
khayakawa | 0:b99a49731909 | 67 | str[4] = '\0'; |
khayakawa | 0:b99a49731909 | 68 | printf("%s\n", str); |
khayakawa | 0:b99a49731909 | 69 | |
khayakawa | 0:b99a49731909 | 70 | |
khayakawa | 0:b99a49731909 | 71 | client.send_all(sendbuf, sizeof(sendbuf)- 1); |
khayakawa | 0:b99a49731909 | 72 | } |
khayakawa | 0:b99a49731909 | 73 | } |