![](/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:
- bridadan
- Date:
- 2015-07-15
- Revision:
- 14:c47437f5dae8
- Parent:
- 11:b7e531a4d661
- Child:
- 15:e48b3c6558b1
File content as of revision 14:c47437f5dae8:
/* 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 "WiFiRadioInterface.h" #include <map> DigitalOut myled(LED1); WiFiRadioInterface 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); SocketInterface* myUDPSocket = wifi.allocateSocket(SOCK_TCP); myTCPSocket->setAddress(myTCPSocket->getHostByName("www.google.com")); myTCPSocket->setAddress("216.58.192.46"); myTCPSocket->setPort(80); myTCPSocket->close(); myUDPSocket->setAddress(myUDPSocket->getHostByName("www.google.com")); myUDPSocket->setAddress("216.58.192.46"); myUDPSocket->setPort(80); myUDPSocket->close(); wifi.disconnect(); while(1) { myled = !myled; } }