Example program for the LWIPInterface

Dependencies:   LWIPInterface NetworkSocketAPI mbed-rtos mbed

Fork of HelloESP8266Interface by NetworkSocketAPI

Example for the NetworkSocketAPI. Attempts to get the device's public facing IP address from ifcfg.me.

Revision:
65:826ec2bbec51
Parent:
59:14d6716bc772
--- a/main.cpp	Tue Apr 19 20:12:25 2016 -0500
+++ b/main.cpp	Wed Apr 20 05:20:12 2016 -0500
@@ -18,41 +18,39 @@
 #include "LWIPInterface.h"
 #include "TCPSocket.h"
 
-DigitalOut myled(LED_GREEN);
-void flash()
+LWIPInterface eth;
+
+DigitalOut led(LED_GREEN);
+void blink()
 {
-    myled = !myled;
+    led = !led;
 }
 
-LWIPInterface eth;
-
 int main()
 {
-    Ticker t;
-    t.attach(flash, 0.4f);
+    Ticker blinky;
+    blinky.attach(blink, 0.4f);
+
     printf("NetworkSocketAPI Example\r\n");
 
     eth.connect();
-
     const char *ip = eth.get_ip_address();
     const char *mac = eth.get_mac_address();
-    printf("IP Address is: %s\r\n", (ip) ? ip : "No IP");
-    printf("MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
+    printf("IP address is: %s\r\n", ip ? ip : "No IP");
+    printf("MAC address is: %s\r\n", mac ? mac : "No MAC");
     
-    SocketAddress addr(&eth, "time-a.nist.gov", 37);
-    printf("time-a.nist.gov resolved to: %s\r\n", addr.get_ip_address());
+    SocketAddress addr(&eth, "mbed.org");
+    printf("mbed.org resolved to: %s\r\n", addr.get_ip_address());
 
     TCPSocket socket(&eth);
-    socket.connect("time-a.nist.gov", 37);
+    socket.connect("4.ifcfg.me", 23);
 
-    char recieved[100] = {0};
-    int32_t size = 0;
-    size = socket.recv(recieved, sizeof(recieved));
-
+    char buffer[64];
+    int count = socket.recv(buffer, sizeof buffer);
+    printf("public IP address is: %.15s\r\n", &buffer[15]);
+    
     socket.close();
     eth.disconnect();
 
-    printf("Recieved: %ld bytes, %02x%02x%02x%02x\r\n", size,
-           recieved[0], recieved[1], recieved[2], recieved[3]);
-    printf("NetworkSocketAPI Example Finished\r\n");
+    printf("Done\r\n");
 }