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:
24:471a07e886ae
Parent:
22:1d355289fc18
Child:
25:eef7d93d9f5b
--- a/main.cpp	Thu Aug 13 15:50:46 2015 +0000
+++ b/main.cpp	Mon Dec 28 06:42:51 2015 +0000
@@ -25,31 +25,31 @@
 int main()
 {
     Ticker t;
-    t.attach(flash, 0.2f);
+    t.attach(flash, 0.4f);
     printf("NetworkSocketAPI Example\r\n");
 
     wifi.init();
-    wifi.connect("iotlab", "42F67YxLX4AawRdcj");
+    wifi.connect("DemoRoom", "");
     
-    char* ip;
-    ip = wifi.getIPAddress();
+    char* 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);
-    
+    wifi.getHostByName("time-a.nist.gov", host_ip);
+    printf("time-a.nist.gov resolved to: %s\n", host_ip);
 
     SocketInterface* mySocket = wifi.allocateSocket(SOCK_TCP);
-    char recieved[100];
+    char recieved[100] = {0};
     int recv_amnt = 0;
     
     //Sending and receiving from echo server 
-    mySocket->setAddressPort("192.168.13.8", 7);
+    mySocket->setAddressPort(host_ip, 37);
     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->send("xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx", 50, 10000);
+    recv_amnt = mySocket->recv(recieved, sizeof(recieved), 10000);
     mySocket->close();
     wifi.disconnect();
+    
+    printf("Recieved: %d bytes, %02x%02x%02x%02x\n", recv_amnt, recieved[0], recieved[1], recieved[2], recieved[3]);
+    printf("NetworkSocketAPI Example Finished\r\n");
+    while(1);
 }