Example program for the ESP8266Interface running Espressif Firmware

Dependencies:   ESP8266Interface NetworkSocketAPI mbed

Note

This example code assumes your ESP8266 is running the Espressif Firmware. For instructions on how to update your ESP8266 to use the correct firmware see the Firmware Update Wiki Page.

This program demonstrates how to open, close, send and recv from the ESP8266 using the Network Socket API.

Revision:
22:1d355289fc18
Parent:
20:4cb9ef3b0cc9
Child:
24:471a07e886ae
--- a/main.cpp	Sun Jul 26 21:55:02 2015 +0000
+++ b/main.cpp	Wed Aug 05 21:59:08 2015 +0000
@@ -29,23 +29,27 @@
     printf("NetworkSocketAPI Example\r\n");
 
     wifi.init();
-    wifi.connect("Buffalo-G-1280", "13808136");
+    wifi.connect("iotlab", "42F67YxLX4AawRdcj");
     
     char* ip;
     ip = wifi.getIPAddress();
     printf("IP Address is: %s\n", (ip) ? ip : "No IP");
+    char host_ip[50];
+    wifi.getHostByName("google.com",host_ip);
+    printf("Google.com resolved to: %s\n",host_ip);
     
-    SocketInterface* mySocket = wifi.allocateSocket(SOCK_UDP);
+
+    SocketInterface* mySocket = wifi.allocateSocket(SOCK_TCP);
     char recieved[100];
     int recv_amnt = 0;
     
-    mySocket->setAddressPort("192.168.13.6", 7);
+    //Sending and receiving from echo server 
+    mySocket->setAddressPort("192.168.13.8", 7);
     mySocket->open();
     mySocket->send("Hello",5, 10000);
     recieved[5] = 0;
     recv_amnt = mySocket->recv(recieved, 5, 10000);
     printf("Recieved: %d, %s\n",recv_amnt, recieved);
-    
     mySocket->close();
     wifi.disconnect();
 }