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:
- 16:bb0a5b830dc5
- Parent:
- 15:e48b3c6558b1
- Child:
- 17:72de842c27b4
--- a/main.cpp Thu Jul 16 05:20:12 2015 +0000 +++ b/main.cpp Fri Jul 17 23:16:57 2015 +0000 @@ -15,38 +15,29 @@ */ #include "mbed.h" -#include "WiFiRadioInterface.h" +#include "ESP8266Interface.h" DigitalOut myled(LED1); -WiFiRadioInterface wifi(D1, D0); +ESP8266Interface wifi(D1, D0); int main() { printf("NetworkSocketAPI Example\r\n"); wifi.init(); - wifi.connect("apname", "phrase", WI_WPA2); - - printf("Wifi is %s\r\n", (wifi.isConnected() > 0) ? "Connected" : "Disconnected"); - - printf("IP: %s\r\n", wifi.getIPAddress()); - printf("Gateway: %s\r\n", wifi.getGateway()); - printf("Mask: %s\r\n", wifi.getNetworkMask()); - printf("MAC: %s\r\n", wifi.getMACAddress()); - - SocketInterface* myTCPSocket = wifi.allocateSocket(SOCK_TCP); + wifi.connect("Buffalo-G-1280", "13808136"); + SocketInterface* myUDPSocket = wifi.allocateSocket(SOCK_UDP); - myTCPSocket->setAddress(myTCPSocket->getHostByName("www.google.com")); - myTCPSocket->setAddress("216.58.192.46"); - myTCPSocket->setPort(80); + myUDPSocket->setAddressPort("192.168.13.5", 7); - myTCPSocket->close(); - - myUDPSocket->setAddress(myUDPSocket->getHostByName("www.google.com")); - myUDPSocket->setAddress("216.58.192.46"); - myUDPSocket->setPort(80); + myUDPSocket->open(); + myUDPSocket->send("Hello",5, 10000); + char recieved[100]; + int recv_amnt = 0; + recv_amnt = myUDPSocket->recv(recieved, 5, 10000); + printf("Recieved: %d, %s\n",recv_amnt,recieved); myUDPSocket->close();