![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Non-blocking example of the LWIPInterface
Dependencies: LWIPInterface NetworkSocketAPI mbed-rtos mbed
Non-blocking example for the NetworkSocketAPI. Attempts to get the device's public facing IP address from ifcfg.me using the Happy Eyeballs algorithm to fetch an IPv4 or IPv6 address.
main.cpp
- Committer:
- sam_grove
- Date:
- 2015-05-14
- Revision:
- 2:7283ce112304
- Parent:
- 0:1984a177ff56
- Child:
- 4:cb8a17dd6746
File content as of revision 2:7283ce112304:
/* NetworkSocketAPI Example Program * Copyright (c) 2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #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 = !myled; } }