Wifi Pressure Sensor
Dependencies: HTTPClient MPL3115A2 NTPClient TMP102 USBDevice cc3000_hostdriver_mbedsocket mbed
Diff: tcpTests.cpp
- Revision:
- 2:8f5776c287c5
- Parent:
- 1:6f4eaec531c4
- Child:
- 3:15828ac052f1
diff -r 6f4eaec531c4 -r 8f5776c287c5 tcpTests.cpp --- a/tcpTests.cpp Mon Nov 04 22:18:14 2013 +0000 +++ b/tcpTests.cpp Tue Nov 12 09:19:13 2013 +0000 @@ -256,6 +256,79 @@ // ------------------------------------------------------------------------------------------------------------ /*! + @brief Open a WebSocket, send a string +*/ +// ------------------------------------------------------------------------------------------------------------ +void WebSocketReadTest ( void ) +{ + +int res = 0; +uint16_t counter = 0; +uint16_t reconnects = 0; +uint8_t myMAC[8]; + + wifi.get_mac_address(myMAC); + + Websocket ws((char *)WEB_SOCKET_URL); + if ( ws.connect() ) + { + pc.printf("Connected to websocket server.\r\n"); + + pc.printf("\r\n!! Press any key to stop receiving !!\r\n\r\n"); + while (1) + { + counter ++; + //sprintf(tmpBuffer, "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]); + + if ( wifi.is_connected() ) + { + res = ws.read(tmpBuffer); + + if ( res ) + { + pc.printf("Websocket Received : %s (Reconnects : %05d, Messages Recv : %05d)\r\n", tmpBuffer, reconnects, counter); + } + + if ( ws.is_connected() ) + { + + } + else + { + pc.printf("Websocket Closed, reconnecting .... \r\n"); + ws.close(); + if ( ws.connect() ) + { + // Reconnected + reconnects ++; + } + else + { + // Failure! + break; + } + } + } + else + { + pc.printf("WiFi Connection Lost .... \r\n"); + } + + if ( pc.readable() ) + { + pc.printf("Closing Socket \r\n"); + pc.getc(); + break; + } + } + + ws.close(); + pc.printf("Websocket Closed \r\n"); + } +} + +// ------------------------------------------------------------------------------------------------------------ +/*! @brief Open a TCP port send a string and wait for a reply */ // ------------------------------------------------------------------------------------------------------------