TCP client see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Dependencies:   GSwifi mbed

Fork of GSwifi_tcpserver by gs fan

Committer:
gsfan
Date:
Tue Aug 21 07:26:08 2012 +0000
Revision:
0:f4c1a7a895ee
Child:
1:fdc165a4df04
1st build
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gsfan 0:f4c1a7a895ee 1 #include "mbed.h"
gsfan 0:f4c1a7a895ee 2 #include "GSwifi.h"
gsfan 0:f4c1a7a895ee 3
gsfan 0:f4c1a7a895ee 4 #define PORT 10080
gsfan 0:f4c1a7a895ee 5
gsfan 0:f4c1a7a895ee 6 #define SECURE GSSEC_WPA_PSK
gsfan 0:f4c1a7a895ee 7 #define SSID "SSID"
gsfan 0:f4c1a7a895ee 8 #define PASS "password"
gsfan 0:f4c1a7a895ee 9
gsfan 0:f4c1a7a895ee 10 GSwifi gs(p13, p14, p12, P0_22); // TX, RX, CTS, RTS
gsfan 0:f4c1a7a895ee 11 Serial pc(USBTX, USBRX);
gsfan 0:f4c1a7a895ee 12 DigitalOut led1(LED1), led2(LED2);
gsfan 0:f4c1a7a895ee 13
gsfan 0:f4c1a7a895ee 14 void onGsReceive (int cid, int len) {
gsfan 0:f4c1a7a895ee 15 int i;
gsfan 0:f4c1a7a895ee 16 char buf[100];
gsfan 0:f4c1a7a895ee 17 Host host;
gsfan 0:f4c1a7a895ee 18
gsfan 0:f4c1a7a895ee 19 led2 = 1;
gsfan 0:f4c1a7a895ee 20
gsfan 0:f4c1a7a895ee 21 i = gs.recv(cid, buf, sizeof(buf));
gsfan 0:f4c1a7a895ee 22 gs.send(cid, buf, i);
gsfan 0:f4c1a7a895ee 23 pc.printf("recv %d\r\n", i);
gsfan 0:f4c1a7a895ee 24 }
gsfan 0:f4c1a7a895ee 25
gsfan 0:f4c1a7a895ee 26 int main () {
gsfan 0:f4c1a7a895ee 27 IpAddr ipaddr, netmask, gateway, nameserver;
gsfan 0:f4c1a7a895ee 28
gsfan 0:f4c1a7a895ee 29 led1 = 1;
gsfan 0:f4c1a7a895ee 30 pc.baud(115200);
gsfan 0:f4c1a7a895ee 31
gsfan 0:f4c1a7a895ee 32 pc.printf("connect\r\n");
gsfan 0:f4c1a7a895ee 33 if (gs.connect(SECURE, SSID, PASS)) {
gsfan 0:f4c1a7a895ee 34 return -1;
gsfan 0:f4c1a7a895ee 35 }
gsfan 0:f4c1a7a895ee 36 gs.getAddress(ipaddr, netmask, gateway, nameserver);
gsfan 0:f4c1a7a895ee 37 pc.printf("ip %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
gsfan 0:f4c1a7a895ee 38
gsfan 0:f4c1a7a895ee 39 pc.printf("listen\r\n");
gsfan 0:f4c1a7a895ee 40 gs.listen(PORT, GSPROT_TCP, &onGsReceive);
gsfan 0:f4c1a7a895ee 41
gsfan 0:f4c1a7a895ee 42 for (;;) {
gsfan 0:f4c1a7a895ee 43 gs.poll();
gsfan 0:f4c1a7a895ee 44
gsfan 0:f4c1a7a895ee 45 wait_ms(50);
gsfan 0:f4c1a7a895ee 46 led1 = !led1;
gsfan 0:f4c1a7a895ee 47 led2 = 0;
gsfan 0:f4c1a7a895ee 48 }
gsfan 0:f4c1a7a895ee 49 }