WizFi250 AP mode, TCP Server Loopback example
Dependencies: WizFi250Interface mbed
Revision 0:c53cb06af402, committed 2016-03-30
- Comitter:
- jehoon
- Date:
- Wed Mar 30 08:01:20 2016 +0000
- Commit message:
- WizFi250 AP TCP Server Loopback example
Changed in this revision
diff -r 000000000000 -r c53cb06af402 WizFi250Interface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WizFi250Interface.lib Wed Mar 30 08:01:20 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/kaizen/code/WizFi250Interface/#f29dd1d06e89
diff -r 000000000000 -r c53cb06af402 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 30 08:01:20 2016 +0000 @@ -0,0 +1,126 @@ +#include "mbed.h" +#include "WizFi250Interface.h" + + +/* AP Info */ +#define SECURE WizFi250::SEC_WPA2_MIXED +#define SSID "WizFi250_AP_TEST" +#define PASS "1234567890" + +/* Socket Info */ +#define PORT 5000 + +Serial pc(USBTX, USBRX); + +/* network setup */ +WizFi250Interface wizfi250(P13,P14,P11,P12,P15,NC,115200); +TCPSocketServer server; +TCPSocketConnection client; + +/* functions */ +int TryApUp(); +int TryServerUp(); +int WaitClient(); +int ApDown(); + +/* variables */ +int isListened = 0; + +int main() +{ + pc.baud(115200); + pc.printf("Start Application AP TCP Server\r\n"); + + + if( TryApUp() < 0 ) return -1; + + if( TryServerUp() < 0 ) return -1; + + if( WaitClient() < 0 ) return -1; + + + while( client.is_connected() ) + { + int len = 0; + char rcvBuf[1024] = {0,}; + + if( wizfi250.readable(0) > 0 ) + { + len = client.receive(rcvBuf, 1023); + if( len > 0 ) + { + client.send(rcvBuf, len); + } + } + } + + + pc.printf("End Application\r\n"); + return 0; +} + + + +int TryApUp() +{ + + if( wizfi250.isAssociated() == 1 ) return -1; + + isListened = 0; + + for(int i= 0; i<5; i++) + { + wizfi250.init(); + wizfi250.setAddress("192.168.0.2","255.255.255.0","192.168.0.2"); + if ( wizfi250.connect(SECURE, SSID, PASS, WizFi250::WM_AP) ) + continue; + else + { + pc.printf("IP Address is %s\r\n", wizfi250.getIPAddress()); + return 0; + } + } + + printf("Fail to make AP\r\n"); + return -1; +} + + +int TryServerUp() +{ + if( wizfi250.isAssociated() != 1 ) return -1; + + if( server.bind(PORT) < 0 ) + { + pc.printf("Bind fail..\r\n"); + return -1; + } + + if( server.listen(1) < 0 ) + { + pc.printf("Listen fail..\r\n"); + return -1; + } + + pc.printf("Listen PORT: %d\r\n",PORT); + isListened = 1; + return 0; +} + +int WaitClient() +{ + + while( isListened ) + { + if( server.accept(client) < 0 ) + { + pc.printf("accept fail..\r\n"); + return -1; + } + + pc.printf("Connection Success!!\r\nIP: %s\r\n", client.get_address()); + return 0; + } + + return -1; +} \ No newline at end of file
diff -r 000000000000 -r c53cb06af402 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 30 08:01:20 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/c0f6e94411f5 \ No newline at end of file