harlequin-tech / WiFlyHQ

WiFly RN-XV Arduino Library
Other
110 stars 68 forks source link

*CLOS* in the output #20

Open faritka opened 11 years ago

faritka commented 11 years ago

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;

}

harlequin-tech commented 11 years ago

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

faritka commented 11 years ago

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