see: http://mbed.org/users/gsfan/notebook/GSwifiInterface/

Dependencies:   GSwifiInterface mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "GSwifiInterface.h"
00003 
00004 #define SEC  GSwifi::SEC_WPA_PSK
00005 #define SSID "SSID"
00006 #define PASS "PASSPHRASE"
00007 
00008 #define ECHO_SERVER_PORT   10000
00009 
00010 int main() {
00011     GSwifiInterface gs(p13, p14, p12, P0_22, p20, NC);
00012     printf("UDP Echo Server...\n");
00013     gs.init(); //Use DHCP
00014     if (gs.connect(SEC, SSID, PASS)) return -1; // join the network
00015     printf("IP Address is %s\n", gs.getIPAddress());
00016     
00017     UDPSocket server;
00018     server.bind(ECHO_SERVER_PORT);
00019     
00020     Endpoint client;
00021     char buffer[256];
00022     while (true) {
00023         printf("\nWait for packet...\n");
00024         int n = server.receiveFrom(client, buffer, sizeof(buffer));
00025         
00026         printf("Received packet from: %s\n", client.get_address());
00027         server.sendTo(client, buffer, n);
00028     }
00029 }