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:
2:7283ce112304
Parent:
0:1984a177ff56
Child:
4:cb8a17dd6746
--- a/main.cpp	Wed May 13 20:17:01 2015 +0000
+++ b/main.cpp	Thu May 14 07:28:56 2015 +0000
@@ -15,15 +15,38 @@
  */
 
 #include "mbed.h"
+#include "WiFiInterface.h"
 
 DigitalOut myled(LED1);
 
+
+WiFiInterface wifi;
+// or
+//NetworkInterface *wifi = new WiFiInterface;
+
+TCPSocket tcp(wifi.getInstance());
+// or
+//SocketInterface tcp = new TCPSocket(wifi->getInstance();
+
+UDPSocket udp(wifi.getInstance());
+// or
+//SocketInterface udp = new UDPSocket(wifi->getInstance();
+
 int main()
 {
+    puts("NetworkSocketAPI Example");
+    
+    wifi.init();
+    wifi.connect("apname", "phrase", WPA2);
+    
+    printf("IP: %s\n", wifi.getIPAddress());
+    printf("Gateway: %s\n", wifi.getGateway());
+    printf("Mask: %s\n", wifi.getNetworkMask());
+    printf("MAC: %s\n", wifi.getMACAddress());
+
+    wifi.disconnect();
+    
     while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+        myled = !myled;
     }
 }