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:
sam_grove
Date:
Thu May 28 20:01:52 2015 +0000
Revision:
4:cb8a17dd6746
Parent:
2:7283ce112304
Child:
6:751245e265f6
Update example: Now functional but failing 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"
sam_grove 2:7283ce112304 18 #include "WiFiInterface.h"
sam_grove 0:1984a177ff56 19
sam_grove 0:1984a177ff56 20 DigitalOut myled(LED1);
sam_grove 0:1984a177ff56 21
sam_grove 2:7283ce112304 22
sam_grove 2:7283ce112304 23 WiFiInterface wifi;
sam_grove 2:7283ce112304 24 // or
sam_grove 2:7283ce112304 25 //NetworkInterface *wifi = new WiFiInterface;
sam_grove 2:7283ce112304 26
sam_grove 4:cb8a17dd6746 27 //TCPSocket tcp(wifi.getInstance());
sam_grove 2:7283ce112304 28 // or
sam_grove 2:7283ce112304 29 //SocketInterface tcp = new TCPSocket(wifi->getInstance();
sam_grove 2:7283ce112304 30
sam_grove 4:cb8a17dd6746 31 //UDPSocket udp(wifi.getInstance());
sam_grove 2:7283ce112304 32 // or
sam_grove 2:7283ce112304 33 //SocketInterface udp = new UDPSocket(wifi->getInstance();
sam_grove 2:7283ce112304 34
sam_grove 0:1984a177ff56 35 int main()
sam_grove 0:1984a177ff56 36 {
sam_grove 2:7283ce112304 37 puts("NetworkSocketAPI Example");
sam_grove 4:cb8a17dd6746 38
sam_grove 2:7283ce112304 39 wifi.init();
sam_grove 4:cb8a17dd6746 40 wifi.connect("apname", "phrase", NetworkInterface::NI_WPA2);
sam_grove 2:7283ce112304 41
sam_grove 4:cb8a17dd6746 42 printf("Wifi is %s\n", (wifi.isConnected() > 0) ? "Connected" : "Disconnected");
sam_grove 4:cb8a17dd6746 43
sam_grove 2:7283ce112304 44 printf("IP: %s\n", wifi.getIPAddress());
sam_grove 2:7283ce112304 45 printf("Gateway: %s\n", wifi.getGateway());
sam_grove 2:7283ce112304 46 printf("Mask: %s\n", wifi.getNetworkMask());
sam_grove 2:7283ce112304 47 printf("MAC: %s\n", wifi.getMACAddress());
sam_grove 2:7283ce112304 48
sam_grove 2:7283ce112304 49 wifi.disconnect();
sam_grove 4:cb8a17dd6746 50
sam_grove 0:1984a177ff56 51 while(1) {
sam_grove 2:7283ce112304 52 myled = !myled;
sam_grove 0:1984a177ff56 53 }
sam_grove 0:1984a177ff56 54 }