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

Dependencies:   GSwifiInterface mbed-rtos mbed

Committer:
gsfan
Date:
Thu Oct 31 08:37:49 2013 +0000
Revision:
0:efb153c0bd96
1st build

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gsfan 0:efb153c0bd96 1 #include "mbed.h"
gsfan 0:efb153c0bd96 2 #include "GSwifiInterface.h"
gsfan 0:efb153c0bd96 3
gsfan 0:efb153c0bd96 4 #define SEC GSwifi::SEC_WPA_PSK
gsfan 0:efb153c0bd96 5 #define SSID "SSID"
gsfan 0:efb153c0bd96 6 #define PASS "PASSPHRASE"
gsfan 0:efb153c0bd96 7
gsfan 0:efb153c0bd96 8 #define ECHO_SERVER_ADDRESS "192.168.1.101"
gsfan 0:efb153c0bd96 9 #define ECHO_SERVER_PORT 10000
gsfan 0:efb153c0bd96 10
gsfan 0:efb153c0bd96 11 int main() {
gsfan 0:efb153c0bd96 12 GSwifiInterface gs(p13, p14, p12, P0_22, p20, NC);
gsfan 0:efb153c0bd96 13 printf("TCP Echo Client...\n");
gsfan 0:efb153c0bd96 14 gs.init(); //Use DHCP
gsfan 0:efb153c0bd96 15 if (gs.connect(SEC, SSID, PASS)) return -1; // join the network
gsfan 0:efb153c0bd96 16 printf("IP Address is %s\n", gs.getIPAddress());
gsfan 0:efb153c0bd96 17
gsfan 0:efb153c0bd96 18 TCPSocketConnection socket;
gsfan 0:efb153c0bd96 19 while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) {
gsfan 0:efb153c0bd96 20 printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
gsfan 0:efb153c0bd96 21 wait(1);
gsfan 0:efb153c0bd96 22 }
gsfan 0:efb153c0bd96 23
gsfan 0:efb153c0bd96 24 char hello[] = "Hello World\n";
gsfan 0:efb153c0bd96 25 socket.send_all(hello, sizeof(hello) - 1);
gsfan 0:efb153c0bd96 26
gsfan 0:efb153c0bd96 27 char buf[256];
gsfan 0:efb153c0bd96 28 int n = socket.receive(buf, 256);
gsfan 0:efb153c0bd96 29 buf[n] = '\0';
gsfan 0:efb153c0bd96 30 printf("%s", buf);
gsfan 0:efb153c0bd96 31
gsfan 0:efb153c0bd96 32 socket.close();
gsfan 0:efb153c0bd96 33 gs.disconnect();
gsfan 0:efb153c0bd96 34
gsfan 0:efb153c0bd96 35 while(true) {}
gsfan 0:efb153c0bd96 36 }