Commit 3fadb77395e7df8670a83d688f393a67ed81cf4a
1 parent
c851f008
--no commit message
Showing
1 changed file
with
15 additions
and
11 deletions
Project/applications/smartcities/httpClient.c
... | ... | @@ -18,6 +18,8 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) |
18 | 18 | |
19 | 19 | char* request; |
20 | 20 | char* response; |
21 | + | |
22 | + err_t connection_ok = -1; | |
21 | 23 | |
22 | 24 | ip4_addr_set_u32(&remote_ip,ipaddr_addr(SERVER_IP)); |
23 | 25 | |
... | ... | @@ -87,20 +89,22 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) |
87 | 89 | netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/ |
88 | 90 | netconn_connect(neocon, &remote_ip, DEFAULT_REMOTE_PORT); |
89 | 91 | |
90 | - // Send Request | |
91 | - printf("httpRequest: Sending request\r\n"); | |
92 | - netconn_write(neocon, request, request_size, NETCONN_NOCOPY); | |
93 | - chHeapFree(request); | |
94 | - | |
95 | - // Wait for Response | |
96 | - printf("httpRequest: Waiting for response\r\n"); | |
97 | - //neocon->recv_timeout = 5000; // for 5s | |
98 | - err_t res=netconn_recv(neocon, &netBufs); | |
99 | - printf("res recv= %d\r\n",res); | |
92 | + while(connection_ok !=0) // != ERR_OK | |
93 | + { | |
94 | + // Send Request | |
95 | + printf("httpRequest: Sending request\r\n"); | |
96 | + netconn_write(neocon, request, request_size, NETCONN_NOCOPY); | |
97 | + chHeapFree(request); | |
98 | + | |
99 | + // Wait for Response | |
100 | + printf("httpRequest: Waiting for response\r\n"); | |
101 | + //neocon->recv_timeout = 5000; // for 5s | |
102 | + connection_ok = netconn_recv(neocon, &netBufs); | |
103 | + printf("res recv= %d\r\n",connection_ok); | |
104 | + } | |
100 | 105 | // Manage Response |
101 | 106 | printf("httpRequest: Response received. Let's parse the information\r\n"); |
102 | 107 | response = (char*)chHeapAlloc(NULL,4*sizeof(char)); |
103 | - printf("gggg\r\n"); | |
104 | 108 | netbuf_copy_partial(netBufs,response,3,9); // read 3B starting from 9th -> read response code. "HTTP/1.1 301 Moved Permanently" |
105 | 109 | printf("httpRequest: Unbelievablelybilbiyblyib successful! :D\r\nResponse code: %s\r\n",response); |
106 | 110 | int http_response = response2int(response); | ... | ... |