Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: wave_player 4DGL-uLCD-SE HC_SR04_Ultrasonic_Library
Diff: main.cpp
- Revision:
- 72:47ae7d8d7321
- Parent:
- 64:a3dc04daaa2a
- Child:
- 76:2d5afdb54c5f
--- a/main.cpp Mon Feb 25 16:41:42 2019 +0000
+++ b/main.cpp Tue Mar 12 13:00:15 2019 +0000
@@ -39,10 +39,10 @@
printf("Netmask: %s\n", netmask ? netmask : "None");
printf("Gateway: %s\n", gateway ? gateway : "None");
- // Open a socket on the network interface, and create a TCP connection to api.ipify.org
+ // Open a socket on the network interface, and create a TCP connection to ifconfig.io
TCPSocket socket;
// Send a simple http request
- char sbuffer[] = "GET / HTTP/1.1\r\nHost: api.ipify.org\r\nConnection: close\r\n\r\n";
+ char sbuffer[] = "GET / HTTP/1.1\r\nHost: ifconfig.io\r\nConnection: close\r\n\r\n";
nsapi_size_t size = strlen(sbuffer);
result = socket.open(net);
@@ -50,7 +50,7 @@
printf("Error! socket.open() returned: %d\n", result);
}
- result = socket.connect("api.ipify.org", 80);
+ result = socket.connect("ifconfig.io", 80);
if (result != 0) {
printf("Error! socket.connect() returned: %d\n", result);
goto DISCONNECT;
@@ -71,7 +71,7 @@
remaining = 256;
rcount = 0;
p = buffer;
- while (0 < (result = socket.recv(p, remaining))) {
+ while (remaining > 0 && 0 < (result = socket.recv(p, remaining))) {
p += result;
rcount += result;
remaining -= result;
@@ -83,9 +83,6 @@
// the HTTP response code
printf("recv %d [%.*s]\n", rcount, strstr(buffer, "\r\n")-buffer, buffer);
- // The api.ipify.org service also gives us the device's external IP address
- p = strstr(buffer, "\r\n\r\n")+4;
- printf("External IP address: %.*s\n", rcount-(p-buffer), p);
delete[] buffer;
DISCONNECT: