see: http://mbed.org/users/gsfan/notebook/GSwifiInterface/
Dependencies: GSwifiInterface mbed-rtos mbed
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("TCP 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 TCPSocketServer server; 00018 server.bind(ECHO_SERVER_PORT); 00019 server.listen(); 00020 00021 while (true) { 00022 printf("\nWait for new connection...\n"); 00023 TCPSocketConnection client; 00024 server.accept(client); 00025 client.set_blocking(false, 1500); // Timeout after (1.5)s 00026 00027 printf("Connection from: %s\n", client.get_address()); 00028 char buffer[256]; 00029 while (true) { 00030 int n = client.receive(buffer, sizeof(buffer)); 00031 if (n <= 0) break; 00032 00033 client.send_all(buffer, n); 00034 if (n <= 0) break; 00035 } 00036 00037 client.close(); 00038 } 00039 }
Generated on Mon Jul 18 2022 22:08:10 by 1.7.2