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

Dependencies:   GSwifiInterface mbed-rtos mbed

Committer:
gsfan
Date:
Thu Oct 31 08:41:25 2013 +0000
Revision:
0:7b52cc18f66f
1st build;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gsfan 0:7b52cc18f66f 1 #include "mbed.h"
gsfan 0:7b52cc18f66f 2 #include "GSwifiInterface.h"
gsfan 0:7b52cc18f66f 3
gsfan 0:7b52cc18f66f 4 #define SEC GSwifi::SEC_WPA_PSK
gsfan 0:7b52cc18f66f 5 #define SSID "SSID"
gsfan 0:7b52cc18f66f 6 #define PASS "PASSPHRASE"
gsfan 0:7b52cc18f66f 7
gsfan 0:7b52cc18f66f 8 #define ECHO_SERVER_PORT 10000
gsfan 0:7b52cc18f66f 9
gsfan 0:7b52cc18f66f 10 int main() {
gsfan 0:7b52cc18f66f 11 GSwifiInterface gs(p13, p14, p12, P0_22, p20, NC);
gsfan 0:7b52cc18f66f 12 printf("UDP Echo Server...\n");
gsfan 0:7b52cc18f66f 13 gs.init(); //Use DHCP
gsfan 0:7b52cc18f66f 14 if (gs.connect(SEC, SSID, PASS)) return -1; // join the network
gsfan 0:7b52cc18f66f 15 printf("IP Address is %s\n", gs.getIPAddress());
gsfan 0:7b52cc18f66f 16
gsfan 0:7b52cc18f66f 17 UDPSocket server;
gsfan 0:7b52cc18f66f 18 server.bind(ECHO_SERVER_PORT);
gsfan 0:7b52cc18f66f 19
gsfan 0:7b52cc18f66f 20 Endpoint client;
gsfan 0:7b52cc18f66f 21 char buffer[256];
gsfan 0:7b52cc18f66f 22 while (true) {
gsfan 0:7b52cc18f66f 23 printf("\nWait for packet...\n");
gsfan 0:7b52cc18f66f 24 int n = server.receiveFrom(client, buffer, sizeof(buffer));
gsfan 0:7b52cc18f66f 25
gsfan 0:7b52cc18f66f 26 printf("Received packet from: %s\n", client.get_address());
gsfan 0:7b52cc18f66f 27 server.sendTo(client, buffer, n);
gsfan 0:7b52cc18f66f 28 }
gsfan 0:7b52cc18f66f 29 }