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.
Diff: main.cpp
- Revision:
- 20:4cb9ef3b0cc9
- Parent:
- 19:03f1da306347
- Child:
- 22:1d355289fc18
--- a/main.cpp Wed Jul 22 20:55:47 2015 +0000 +++ b/main.cpp Sun Jul 26 21:55:02 2015 +0000 @@ -18,11 +18,14 @@ #include "ESP8266Interface.h" DigitalOut myled(LED1); +void flash(){myled = !myled;} ESP8266Interface wifi(D1, D0); int main() -{ +{ + Ticker t; + t.attach(flash, 0.2f); printf("NetworkSocketAPI Example\r\n"); wifi.init(); @@ -30,29 +33,19 @@ char* ip; ip = wifi.getIPAddress(); - if(ip!=NULL) - printf("IP Address is: %s",ip); - else - printf("No IP"); + printf("IP Address is: %s\n", (ip) ? ip : "No IP"); SocketInterface* mySocket = wifi.allocateSocket(SOCK_UDP); - + char recieved[100]; + int recv_amnt = 0; mySocket->setAddressPort("192.168.13.6", 7); - mySocket->open(); mySocket->send("Hello",5, 10000); - char recieved[100]; - int recv_amnt = 0; recieved[5] = 0; recv_amnt = mySocket->recv(recieved, 5, 10000); - printf("Recieved: %d, %s\n",recv_amnt,recieved); + printf("Recieved: %d, %s\n",recv_amnt, recieved); mySocket->close(); - wifi.disconnect(); - - while(1) { - myled = !myled; - } }