I try to make subsequent calls to retrieve multiple files from a server.
The flag "connected" is unreliable. In the first call, it's true. In the second, after "open" it's true, then suddenly it's false.
Because this flag is incorrect, when I download a file and save it on the SD card, it's 6 bytes longer because of the added "CLOS" phrase inside of the WiFly stream.
The main problem is in the function "available":
int WiFly::available()
{
int count;
count = serial->available();
if (count > 0) {
if (debugOn) {
debug.print(F("available: peek = "));
debug.println((char)serial->peek());
}
/* Check for TCP stream closure */
if (serial->peek() == '*') {
if (connected) {
if (checkClose(true)) {
return -1;
} else {
return peekCount + serial->available();
}
} else {
checkOpen(true);
return peekCount + serial->available();
}
}
}
return count+peekCount;
}
I modified it to always check for the "CLOS" statement, connected or not, and now files are correct.
int WiFly::available()
{
int count;
count = serial->available();
if (count > 0) {
if (debugOn) {
debug.print(F("available: peek = "));
debug.println((char)serial->peek());
}
/* Check for TCP stream closure */
if (serial->peek() == '*') {
if (checkClose(true)) {
return -1;
} else {
return peekCount + serial->available();
}
if (!connected) {
checkOpen(true);
return peekCount + serial->available();
}
}
}
return count+peekCount;
I try to make subsequent calls to retrieve multiple files from a server.
The flag "connected" is unreliable. In the first call, it's true. In the second, after "open" it's true, then suddenly it's false.
Because this flag is incorrect, when I download a file and save it on the SD card, it's 6 bytes longer because of the added "CLOS" phrase inside of the WiFly stream.
The main problem is in the function "available":
int WiFly::available() { int count;
}
I modified it to always check for the "CLOS" statement, connected or not, and now files are correct.
int WiFly::available() { int count;
}