![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mearm colorsorting with web application
Diff: main.cpp
- Revision:
- 3:f5e5af908b55
- Parent:
- 1:ec61ea9f67de
- Child:
- 4:62b6eaf030ab
diff -r e72bc303ea90 -r f5e5af908b55 main.cpp --- a/main.cpp Mon Jun 26 09:28:54 2017 +0000 +++ b/main.cpp Thu Nov 30 16:10:23 2017 +0000 @@ -6,7 +6,9 @@ #include "EthernetInterface.h" #include "TCPServer.h" #include "TCPSocket.h" - +uint8_t http[1024]; +//static uint8_t resp[1024]; +static void SendWebPage(float temperature); #define HTTP_STATUS_LINE "HTTP/1.0 200 OK" #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" #define HTTP_MESSAGE_BODY "" \ @@ -23,11 +25,15 @@ HTTP_HEADER_FIELDS "\r\n" \ "\r\n" \ HTTP_MESSAGE_BODY "\r\n" + + int main() { + float v = 7; printf("Basic HTTP server example\n"); + EthernetInterface eth; eth.connect(); @@ -45,10 +51,48 @@ /* Can handle 5 simultaneous connections */ srv.listen(5); - + while (true) { - srv.accept(&clt_sock, &clt_addr); + + SendWebPage(v); + srv.accept(&clt_sock, &clt_addr); printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); - clt_sock.send(HTTP_RESPONSE, strlen(HTTP_RESPONSE)); + //clt_sock.send(HTTP_RESPONSE, strlen(HTTP_RESPONSE)); + clt_sock.send(http, strlen((char *)http)); + + v++; + SendWebPage(v); + clt_sock.send(http, strlen((char *)http)); } + } + +static void SendWebPage( float temperature) +{ + uint8_t temp[50]; + //uint16_t SentDataLength; + //WIFI_Status_t ret; + + /* construct web page content */ + strcpy((char *)http, (char *)"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"); + strcat((char *)http, (char *)"<html>\r\n<body>\r\n"); + strcat((char *)http, (char *)"<head>\r\n"); + strcat((char *)http, (char *)"<meta http-equiv="refresh" content="30">\r\n"); + strcat((char *)http, (char *)"</head>\r\n"); + strcat((char *)http, (char *)"<title>STM32 Web Server</title>\r\n"); + strcat((char *)http, (char *)"<h2>InventekSys : Web Server using Es-Wifi with STM32</h2>\r\n"); + strcat((char *)http, (char *)"<br /><hr>\r\n"); + strcat((char *)http, (char *)"<p><form method=\"POST\"><strong>Temp: <input type=\"text\" size=2 value=\""); + sprintf((char *)temp, "%f", temperature); + strcat((char *)http, (char *)temp); + strcat((char *)http, (char *)"</body>\r\n</html>\r\n"); + + //ret = WIFI_SendData(0, (uint8_t *)http, strlen((char *)http), &SentDataLength, WIFI_WRITE_TIMEOUT); + + // if((ret == WIFI_STATUS_OK) && (SentDataLength != strlen((char *)http))) + //{ + // ret = WIFI_STATUS_ERROR; + // } + + // return 0; +}