Khakimov Rishat
/
Kurs
87ty78ot7iyu
Diff: main.cpp
- Revision:
- 91:dab9882e2b49
- Parent:
- 77:b74ac6641a3e
- Child:
- 100:818629f882ab
--- a/main.cpp Wed Jan 09 09:30:03 2019 +0000 +++ b/main.cpp Wed Jan 09 14:30:04 2019 +0000 @@ -15,7 +15,6 @@ */ #include "mbed.h" -#include "TCPSocket.h" WiFiInterface *wifi; @@ -73,60 +72,8 @@ return count; } -void http_demo(NetworkInterface *net) -{ - TCPSocket socket; - nsapi_error_t response; - - printf("Sending HTTP request to www.arm.com...\n"); - - // Open a socket on the network interface, and create a TCP connection to www.arm.com - response = socket.open(net); - if(0 != response) { - printf("socket.open() failed: %d\n", response); - return; - } - - response = socket.connect("api.ipify.org", 80); - if(0 != response) { - printf("Error connecting: %d\n", response); - socket.close(); - return; - } - - // Send a simple http request - char sbuffer[] = "GET / HTTP/1.1\r\nHost: api.ipify.org\r\nConnection: close\r\n\r\n"; - nsapi_size_t size = strlen(sbuffer); - - // Loop until whole request send - while(size) { - response = socket.send(sbuffer+response, size); - if (response < 0) { - printf("Error sending data: %d\n", response); - socket.close(); - return; - } - size -= response; - printf("sent %d [%.*s]\n", response, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); - } - - // Receieve a simple http response and print out the response line - char rbuffer[64]; - response = socket.recv(rbuffer, sizeof rbuffer); - if (response < 0) { - printf("Error receiving data: %d\n", response); - } else { - printf("recv %d [%.*s]\n", response, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); - } - - // Close the socket to return its memory and bring down the network interface - socket.close(); -} - int main() { - int count = 0; - printf("WiFi example\n"); #ifdef MBED_MAJOR_VERSION @@ -139,9 +86,9 @@ return -1; } - count = scan_demo(wifi); + int count = scan_demo(wifi); if (count == 0) { - printf("No WIFI APNs found - can't continue further.\n"); + printf("No WIFI APs found - can't continue further.\n"); return -1; } @@ -159,8 +106,6 @@ printf("Gateway: %s\n", wifi->get_gateway()); printf("RSSI: %d\n\n", wifi->get_rssi()); - http_demo(wifi); - wifi->disconnect(); printf("\nDone\n");