Example program for the BSDInterface
Dependencies: BSDInterface NetworkSocketAPI
Fork of HelloLWIPInterface by
Revision 14:c47437f5dae8, committed 2015-07-15
- Comitter:
- bridadan
- Date:
- Wed Jul 15 23:23:14 2015 +0000
- Parent:
- 13:561fd2a6fb00
- Child:
- 15:e48b3c6558b1
- Commit message:
- Updating libraries and example program to match new APIs.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ATParser.lib Wed Jul 15 23:23:14 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/NetworkSocketAPI/code/ATParser/#c741e144517c
--- a/NetworkSocketAPI.lib Wed Jul 15 19:53:51 2015 +0000 +++ b/NetworkSocketAPI.lib Wed Jul 15 23:23:14 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/#50b0a3f840df +http://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/#47c32687a44c
--- a/WiFiRadioInterface.lib Wed Jul 15 19:53:51 2015 +0000 +++ b/WiFiRadioInterface.lib Wed Jul 15 23:23:14 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/NetworkSocketAPI/code/WiFiRadioInterface/#d29439d50306 +http://developer.mbed.org/teams/NetworkSocketAPI/code/WiFiRadioInterface/#b2f781416464
--- a/main.cpp Wed Jul 15 19:53:51 2015 +0000 +++ b/main.cpp Wed Jul 15 23:23:14 2015 +0000 @@ -16,49 +16,43 @@ #include "mbed.h" #include "WiFiRadioInterface.h" +#include <map> DigitalOut myled(LED1); -WiFiRadioInterface 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(); +WiFiRadioInterface wifi(D1, D0); int main() -{ - puts("NetworkSocketAPI Example"); +{ + printf("NetworkSocketAPI Example\r\n"); wifi.init(); wifi.connect("apname", "phrase", WI_WPA2); - printf("Wifi is %s\n", (wifi.isConnected() > 0) ? "Connected" : "Disconnected"); + printf("Wifi is %s\r\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()); + 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); - //Endpoint google; - wifi.set_address(wifi.get_host_by_name("www.google.com")); - wifi.set_address("216.58.192.46"); - wifi.set_port(80); + myTCPSocket->setAddress(myTCPSocket->getHostByName("www.google.com")); + myTCPSocket->setAddress("216.58.192.46"); + myTCPSocket->setPort(80); + + myTCPSocket->close(); - //Socket socket; - char buf[1024]; - wifi.open(*wifi.endpoint); - wifi.recv(buf, 1024); - wifi.send(buf, sizeof(buf)); - wifi.close(*wifi.endpoint); - + myUDPSocket->setAddress(myUDPSocket->getHostByName("www.google.com")); + myUDPSocket->setAddress("216.58.192.46"); + myUDPSocket->setPort(80); + + myUDPSocket->close(); + wifi.disconnect(); - + while(1) { myled = !myled; }