Just a test

Dependencies:   BSP_DISCO_F769NI LCD_DISCO_F769NI lcd_log esp8266-driver

Fork of mbed-os-example-blinky-5 by Joscha Ihl

Committer:
joschaihl
Date:
Sun Dec 17 22:55:57 2017 +0000
Revision:
9:adfdb4ba838b
Parent:
8:084f05e528ba
ba

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joschaihl 8:084f05e528ba 1 #if !FEATURE_LWIP
joschaihl 8:084f05e528ba 2 #error [NOT_SUPPORTED] LWIP not supported for this target
joschaihl 8:084f05e528ba 3 #endif
joschaihl 8:084f05e528ba 4
joschaihl 8:084f05e528ba 5
joschaihl 8:084f05e528ba 6 #include "EthernetInterface.h"
joschaihl 8:084f05e528ba 7 #include "TCPServer.h"
joschaihl 8:084f05e528ba 8 #include "TCPSocket.h"
joschaihl 8:084f05e528ba 9
joschaihl 8:084f05e528ba 10 #define HTTP_STATUS_LINE "HTTP/1.0 200 OK"
joschaihl 8:084f05e528ba 11 #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8"
joschaihl 8:084f05e528ba 12 #define HTTP_MESSAGE_BODY "" \
joschaihl 8:084f05e528ba 13 "<html>" "\r\n" \
joschaihl 8:084f05e528ba 14 " <body style=\"display:flex;text-align:center\">" "\r\n" \
joschaihl 8:084f05e528ba 15 " <div style=\"margin:auto\">" "\r\n" \
joschaihl 8:084f05e528ba 16 " <h1>Hello World</h1>" "\r\n" \
joschaihl 8:084f05e528ba 17 " <p>It works !</p>" "\r\n" \
joschaihl 8:084f05e528ba 18 " </div>" "\r\n" \
joschaihl 8:084f05e528ba 19 " </body>" "\r\n" \
joschaihl 8:084f05e528ba 20 "</html>"
joschaihl 8:084f05e528ba 21
joschaihl 8:084f05e528ba 22 #define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n" \
joschaihl 8:084f05e528ba 23 HTTP_HEADER_FIELDS "\r\n" \
joschaihl 8:084f05e528ba 24 "\r\n" \
joschaihl 8:084f05e528ba 25 HTTP_MESSAGE_BODY "\r\n"
joschaihl 8:084f05e528ba 26
joschaihl 8:084f05e528ba 27 void srvLoop()
joschaihl 8:084f05e528ba 28 {
joschaihl 8:084f05e528ba 29 printf("Basic HTTP server example\n");
joschaihl 8:084f05e528ba 30
joschaihl 8:084f05e528ba 31 EthernetInterface eth;
joschaihl 8:084f05e528ba 32 eth.connect();
joschaihl 8:084f05e528ba 33
joschaihl 8:084f05e528ba 34 printf("The target IP address is '%s'\n", eth.get_ip_address());
joschaihl 8:084f05e528ba 35
joschaihl 8:084f05e528ba 36 TCPServer srv;
joschaihl 8:084f05e528ba 37 TCPSocket clt_sock;
joschaihl 8:084f05e528ba 38 SocketAddress clt_addr;
joschaihl 8:084f05e528ba 39
joschaihl 8:084f05e528ba 40 /* Open the server on ethernet stack */
joschaihl 8:084f05e528ba 41 srv.open(&eth);
joschaihl 8:084f05e528ba 42
joschaihl 8:084f05e528ba 43 /* Bind the HTTP port (TCP 80) to the server */
joschaihl 8:084f05e528ba 44 srv.bind(eth.get_ip_address(), 80);
joschaihl 8:084f05e528ba 45
joschaihl 8:084f05e528ba 46 /* Can handle 5 simultaneous connections */
joschaihl 8:084f05e528ba 47 srv.listen(5);
joschaihl 8:084f05e528ba 48
joschaihl 8:084f05e528ba 49 while (true) {
joschaihl 8:084f05e528ba 50 srv.accept(&clt_sock, &clt_addr);
joschaihl 8:084f05e528ba 51 printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port());
joschaihl 8:084f05e528ba 52 clt_sock.send(HTTP_RESPONSE, strlen(HTTP_RESPONSE));
joschaihl 8:084f05e528ba 53 }
joschaihl 8:084f05e528ba 54 }