![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Cubic Hand project for EECS 249A course.
Dependencies: MMA8451Q TSI cc3000_hostdriver_mbedsocket NVIC_set_all_priorities mbed Multi_WS2811
Diff: GloveWifi.cpp
- Revision:
- 15:b48ac00af0b8
- Parent:
- 14:0c4a26dc6873
- Child:
- 19:e751d075e2e6
--- a/GloveWifi.cpp Sun Dec 07 19:50:47 2014 +0000 +++ b/GloveWifi.cpp Sun Dec 07 21:49:33 2014 +0000 @@ -47,7 +47,6 @@ //wifi = new cc3000(PTD4, PTC9, PTD0, SPI(PTD2, PTD3, PTD1), SSID, PASSWORD, WPA2, false); wifi = new cc3000(PTD4, PTC9, PTC4, SPI(PTC6, PTC7, PTC5), SSID, PASSWORD, WPA2, false); wifi->init(); - socket = new TCPSocketConnection; if (wifi->connect() == -1) { printf("Failed to connect. Please verify connection details and try again. \r\n"); @@ -55,6 +54,7 @@ { printf("IP address: %s \r\n", wifi->getIPAddress()); } + socket = new TCPSocketConnection; while (socket->connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) { printf("Unable to connect to (%s) on port (%d) \r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); @@ -62,6 +62,7 @@ } socket->set_blocking(true); printf("Connected!\r\n"); + } void GloveWifi::Disconnect() @@ -72,8 +73,22 @@ delete wifi; } +void GloveWifi::Reconnect() +{ + delete socket; + socket = new TCPSocketConnection; + while (socket->connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) + { + printf("Unable to connect to (%s) on port (%d) \r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); + wait(1); + } + socket->set_blocking(true); + printf("Reconnected!\r\n"); +} + uint8_t GloveWifi::GetDataFromBuffer(uint8_t * buf, uint16_t size) { + //printf("Buffer Size: %d\r\n", wifi->_simple_link.get_transmit_error()); return socket->receive((char *)buf, size); }