![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mearm colorsorting with web application
Diff: main.cpp
- Revision:
- 5:36f1e4e1a427
- Parent:
- 4:62b6eaf030ab
- Child:
- 6:60ab0d214512
diff -r 62b6eaf030ab -r 36f1e4e1a427 main.cpp --- a/main.cpp Thu Nov 30 17:10:05 2017 +0000 +++ b/main.cpp Thu Dec 14 12:48:11 2017 +0000 @@ -1,36 +1,32 @@ -#if !FEATURE_LWIP - #error [NOT_SUPPORTED] LWIP not supported for this target -#endif +//#if !FEATURE_LWIP + // #error [NOT_SUPPORTED] LWIP not supported for this target +//#endif #include "mbed.h" #include "EthernetInterface.h" #include "TCPServer.h" #include "TCPSocket.h" +#include "Servo.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 "" \ -"<html>" "\r\n" \ -" <body style=\"display:flex;text-align:center\">" "\r\n" \ -" <div style=\"margin:auto\">" "\r\n" \ -" <h1>Hello World</h1>" "\r\n" \ -" <p>It works !</p>" "\r\n" \ -" </div>" "\r\n" \ -" </body>" "\r\n" \ -"</html>" +uint8_t httpr[1024]={200,200}; +uint8_t httpr1[300]={2,2,2,2}; +//static void SendWebPage( float ,float ,float , float ); -#define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n" \ - HTTP_HEADER_FIELDS "\r\n" \ - "\r\n" \ - HTTP_MESSAGE_BODY "\r\n" - + int main() { - float v = 7; + Servo Servo1(PD_13); + Servo Servo2(PD_12); + Servo Servo3(PD_14); + Servo Servo4(PD_15); + + Servo1.Enable(1500,20000); + Servo2.Enable(1500,20000); + Servo3.Enable(1500,20000); + + int pos,i=0,a=0,a1=0; printf("Basic HTTP server example\n"); @@ -40,57 +36,51 @@ printf("The target IP address is '%s'\n", eth.get_ip_address()); TCPServer srv; + TCPSocket clt_sock; + SocketAddress clt_addr; + /* Open the server on ethernet stack */ srv.open(ð); + /* Bind the HTTP port (TCP 80) to the server */ - srv.bind(eth.get_ip_address(), 80); + //srv.bind(eth.get_ip_address(), 80); + srv.bind(eth.get_ip_address(), 5001); + // srv1.bind("10.101.1.130",5001); /* Can handle 5 simultaneous connections */ srv.listen(5); + while (true) { - 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, strlen((char *)http)); - v++; - - } - -} + //========================== + for ( pos = 500; pos < 2000; pos += 25) + { + Servo1.SetPosition(pos); + httpr[i]=8; + wait_ms(20); + i++; + } -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<meta http-equiv=""refresh"" content=""30"">\r\n</head>\r\n"); - //strcat((char *)http, (char *)); - //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; -} + //i=0; + // SendWebPage(pos,v2,v3,v4); + srv.accept(&clt_sock, &clt_addr); + printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); + a = clt_sock.send(httpr, strlen((char *)httpr)); + while(true) + { + a1 = clt_sock.recv(httpr1, strlen((char *)httpr1)); + //printf("accept Xbyte %d\n",a1); + if (a1 <= 0) + break; + //httpr1[a1] = '\0'; + printf("Received %d chars from server:\n%s\n", a1,httpr1); + } + clt_sock.close(); + printf("accept voir %d\n",httpr1[0]); + } +