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.
Diff: main.cpp
- Revision:
- 4:cb8a17dd6746
- Parent:
- 2:7283ce112304
- Child:
- 6:751245e265f6
--- a/main.cpp Thu May 28 16:48:17 2015 +0000 +++ b/main.cpp Thu May 28 20:01:52 2015 +0000 @@ -24,28 +24,30 @@ // or //NetworkInterface *wifi = new WiFiInterface; -TCPSocket tcp(wifi.getInstance()); +//TCPSocket tcp(wifi.getInstance()); // or //SocketInterface tcp = new TCPSocket(wifi->getInstance(); -UDPSocket udp(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); + wifi.connect("apname", "phrase", NetworkInterface::NI_WPA2); + printf("Wifi is %s\n", (wifi.isConnected() > 0) ? "Connected" : "Disconnected"); + 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; }