Example program for the BSDInterface

Dependencies:   BSDInterface NetworkSocketAPI

Fork of HelloLWIPInterface by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
Christopher Haster
Date:
Mon Feb 22 23:58:09 2016 -0600
Branch:
api-changes
Parent:
29:469d33b3ea1e
Child:
31:3269075873dc
Commit message:
Matched changes in NetworkSocketAPI

Changed in this revision

ESP8266Interface.lib Show annotated file Show diff for this revision Revisions of this file
NetworkSocketAPI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ESP8266Interface.lib	Tue Feb 23 18:21:23 2016 +0000
+++ b/ESP8266Interface.lib	Mon Feb 22 23:58:09 2016 -0600
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/NetworkSocketAPI/code/ESP8266Interface/#276cb279df57
+https://developer.mbed.org/teams/NetworkSocketAPI/code/ESP8266Interface/#9c26a3dcdc1f
--- a/NetworkSocketAPI.lib	Tue Feb 23 18:21:23 2016 +0000
+++ b/NetworkSocketAPI.lib	Mon Feb 22 23:58:09 2016 -0600
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/#157fb2ab965f
+http://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/#11d4a94df3f7
--- a/main.cpp	Tue Feb 23 18:21:23 2016 +0000
+++ b/main.cpp	Mon Feb 22 23:58:09 2016 -0600
@@ -16,11 +16,13 @@
 
 #include "mbed.h"
 #include "ESP8266Interface.h"
+#include "TCPSocket.h"
 
 DigitalOut myled(LED1);
-void flash(){myled = !myled;}
+void flash(){ myled = !myled; }
 
 ESP8266Interface wifi(D1, D0);
+TCPSocket socket(&wifi);
 
 int main()
 {
@@ -28,28 +30,24 @@
     t.attach(flash, 0.4f);
     printf("NetworkSocketAPI Example\r\n");
 
-    wifi.init();
     wifi.connect("WifiDemo", "");
     
-    char* ip = wifi.getIPAddress();
-    printf("IP Address is: %s\n", (ip) ? ip : "No IP");
-    char host_ip[50];
-    wifi.getHostByName("time-a.nist.gov", host_ip);
-    printf("time-a.nist.gov resolved to: %s\n", host_ip);
+    const char *ip = wifi.getIPAddress();
+    const char *mac = wifi.getMACAddress();
+    printf("IP Address is: %s\r\n", (ip) ? ip : "No IP");
+    printf("MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
 
-    SocketInterface* mySocket = wifi.allocateSocket(SOCK_TCP);
+    socket.open("time-a.nist.gov", 37);
+    printf("time-a.nist.gov resolved to: %s\r\n", socket.getIPAddress());
+
     char recieved[100] = {0};
-    int recv_amnt = 0;
-    
-    //Sending and receiving from echo server
-    mySocket->setAddressPort(host_ip, 37);
-    mySocket->open();
-    //mySocket->send("xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx", 50, 10000);
-    recv_amnt = mySocket->recv(recieved, sizeof(recieved), 10000);
-    mySocket->close();
+    int32_t size = 0;
+    size = socket.recv(recieved, sizeof(recieved));
+
+    socket.close();
     wifi.disconnect();
-    
-    printf("Recieved: %d bytes, %02x%02x%02x%02x\n", recv_amnt, recieved[0], recieved[1], recieved[2], recieved[3]);
+
+    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");
-    while(1);
 }