WiFi DipCortex / CC3000 Demo - Contains a menu driven set of tests to initalise and control the CC3000 radio. Also allowing you to test various TCP and UDP connections.
Dependencies: NTPClient WebSocketClient cc3000_hostdriver_mbedsocket mbed HTTPClient
http://www.soldersplash.co.uk/products/wifi-dipcortex/
Please Note, this example uses the serial port so you will need an external RS232 TTL to USB adapter.
Diff: tcpTests.cpp
- Revision:
- 5:506f580e7ead
- Parent:
- 4:4e5e094a81c0
--- a/tcpTests.cpp Wed Oct 09 00:59:47 2013 +0000 +++ b/tcpTests.cpp Sat Oct 12 22:10:17 2013 +0000 @@ -111,26 +111,34 @@ { counter ++; sprintf(websocketstr, "WiFi DipCortex / CC3000 - %05d - %02x:%02x:%02x:%02x:%02x:%02x\r\n", counter, myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]); - res = ws.send(websocketstr); - printf("Reconnects : %05d, Messages Sent : %05d, Websocket send returned : %d.\r\n", reconnects, counter, res); - - if ( -1 == res ) + + if ( wifi.is_connected() ) { - printf("Websocket Failure, reconnecting .... \r\n"); - ws.close(); - if ( ws.connect() ) + res = ws.send(websocketstr); + printf("Reconnects : %05d, Messages Sent : %05d, Websocket send returned : %d.\r\n", reconnects, counter, res); + + if ( -1 == res ) { - // Reconnected - reconnects ++; + printf("Websocket Failure, reconnecting .... \r\n"); + ws.close(); + if ( ws.connect() ) + { + // Reconnected + reconnects ++; + } + else + { + // Failure! + break; + } } - else - { - // Failure! - break; - } + + wait_ms(1000); } - - wait_ms(1000); + else + { + printf("WiFi Connection Lost .... \r\n"); + } if ( pc.readable() ) { @@ -192,7 +200,7 @@ else { buf[0] = '\0'; - printf("Failed to Recv\r\n"); + printf("TCP : Failed to Recv\r\n"); break; } @@ -205,7 +213,10 @@ break; } } - socket.close(); + if ( wifi.is_connected() ) + { + socket.close(); + } printf("Completed.\r\n"); } } @@ -246,5 +257,15 @@ pc.getc(); break; } + + if ( wifi.is_connected() ) + { + break; + } + } + + if ( wifi.is_connected() ) + { + server.close(); } } \ No newline at end of file