WiFlyHQ icon indicating copy to clipboard operation
WiFlyHQ copied to clipboard

*CLOS* in the output

Open faritka opened this issue 13 years ago • 2 comments

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;

}

faritka avatar Mar 29 '13 16:03 faritka

Thanks for the bug report. I'll try out your fix and see if I can fix the connected flag status.

harlequin-tech avatar Apr 04 '13 09:04 harlequin-tech

It won't fix the connected flag. At least, it'll delete the CLOS string from the incoming data.

faritka avatar Apr 05 '13 19:04 faritka