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.

Committer:
sarahmarshy
Date:
Fri Jul 17 23:16:57 2015 +0000
Revision:
16:bb0a5b830dc5
Parent:
15:e48b3c6558b1
Child:
17:72de842c27b4
Test UDP socket dev and ESP8266 implementation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:1984a177ff56 1 /* NetworkSocketAPI Example Program
sam_grove 0:1984a177ff56 2 * Copyright (c) 2015 ARM Limited
sam_grove 0:1984a177ff56 3 *
sam_grove 0:1984a177ff56 4 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 0:1984a177ff56 5 * you may not use this file except in compliance with the License.
sam_grove 0:1984a177ff56 6 * You may obtain a copy of the License at
sam_grove 0:1984a177ff56 7 *
sam_grove 0:1984a177ff56 8 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 0:1984a177ff56 9 *
sam_grove 0:1984a177ff56 10 * Unless required by applicable law or agreed to in writing, software
sam_grove 0:1984a177ff56 11 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 0:1984a177ff56 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 0:1984a177ff56 13 * See the License for the specific language governing permissions and
sam_grove 0:1984a177ff56 14 * limitations under the License.
sam_grove 0:1984a177ff56 15 */
sam_grove 0:1984a177ff56 16
sam_grove 0:1984a177ff56 17 #include "mbed.h"
sarahmarshy 16:bb0a5b830dc5 18 #include "ESP8266Interface.h"
sam_grove 0:1984a177ff56 19
sam_grove 0:1984a177ff56 20 DigitalOut myled(LED1);
sam_grove 0:1984a177ff56 21
sarahmarshy 16:bb0a5b830dc5 22 ESP8266Interface wifi(D1, D0);
sam_grove 2:7283ce112304 23
sam_grove 0:1984a177ff56 24 int main()
bridadan 14:c47437f5dae8 25 {
bridadan 14:c47437f5dae8 26 printf("NetworkSocketAPI Example\r\n");
sam_grove 4:cb8a17dd6746 27
sam_grove 2:7283ce112304 28 wifi.init();
sarahmarshy 16:bb0a5b830dc5 29 wifi.connect("Buffalo-G-1280", "13808136");
sarahmarshy 16:bb0a5b830dc5 30
sam_grove 15:e48b3c6558b1 31 SocketInterface* myUDPSocket = wifi.allocateSocket(SOCK_UDP);
sam_grove 9:da5a230fa4f4 32
sarahmarshy 16:bb0a5b830dc5 33 myUDPSocket->setAddressPort("192.168.13.5", 7);
bridadan 14:c47437f5dae8 34
sarahmarshy 16:bb0a5b830dc5 35 myUDPSocket->open();
sarahmarshy 16:bb0a5b830dc5 36 myUDPSocket->send("Hello",5, 10000);
sarahmarshy 16:bb0a5b830dc5 37 char recieved[100];
sarahmarshy 16:bb0a5b830dc5 38 int recv_amnt = 0;
sarahmarshy 16:bb0a5b830dc5 39 recv_amnt = myUDPSocket->recv(recieved, 5, 10000);
sarahmarshy 16:bb0a5b830dc5 40 printf("Recieved: %d, %s\n",recv_amnt,recieved);
bridadan 14:c47437f5dae8 41
bridadan 14:c47437f5dae8 42 myUDPSocket->close();
bridadan 14:c47437f5dae8 43
sam_grove 2:7283ce112304 44 wifi.disconnect();
bridadan 14:c47437f5dae8 45
sam_grove 0:1984a177ff56 46 while(1) {
sam_grove 2:7283ce112304 47 myled = !myled;
sam_grove 0:1984a177ff56 48 }
sam_grove 0:1984a177ff56 49 }