Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 11 months ago.
Problem with TCP Client over Wifly
Hi everyone, i have a problem with making a tcp client in mbed using David Smart's Wifly library. When i sent a char array with the send command first i receive an exit string (that i never sent). Looking in the DEBUG mode of the WIFLY library, it seems that is tooking too long to open the connection to the server and then the enter cmd mode fails.
Please help me
Greetings
Ney
1 Answer
9 years, 11 months ago.
Hi Ney,
I've found different Wifly modules (most likely related to the firmware version) have different timing characteristics for the commands. In the Wifly driver file, you'll find "FlushIn()" called, which clears any leftover characters. I recently found a few stray characters were not flushed before transitioning the interface from command mode back to data. The default amount of time to wait is 1 ms, but increasing it to 5 solved it (for me). In an attempt to reduce any unnecessary delays, I guess I took it too far.
int Wifly::send(const char * str, int len, const char * ACK, char * res, int timeout) { ... if (tolower(read) == tolower(ACK[ackIndex])) { ackIndex++; if (ackIndex == strlen(ACK)) { //flushIn(); flushIn(5); // this small delay let's is remove trailing parts of a command break; } }
I don't know if this is the same place that it interfering with your application, but it might be the easy thing to try first.
Hi David i saw that when i open a tcp connection and then sent a string the command mode exit automatically. I deactivate this two lines in your code:
bool Wifly::connect(const char * host, int port) { char rcv[20]; char cmd[20]; // try to open sprintf(cmd, "open %s %d\r", host, port); if (sendCommand(cmd, "OPEN", NULL, 10000)) { setConnectionState(true); //exit(); return true; } // if failed, retry and parse the response if (sendCommand(cmd, NULL, rcv, 5000)) { if (strstr(rcv, "OPEN") == NULL) { if (strstr(rcv, "Connected") != NULL) { if (!sendCommand("close\r", "CLOS")) return false; if (!sendCommand(cmd, "OPEN", NULL, 10000)) return false; } else { return false; } } } else { return false; } setConnectionState(true); //exit(); return true; }
And then i resolve the problem of strange strings (blank and exit string)
I will try your solution
Greetings
posted by 25 Sep 2014