I’m using my board to run a small web server using the Alpha 1 driver. Generally it is working fine thanks to all the effort here. The only problem I still have is with the data being returned from the WiFly. Specifically, I’m trying to parse the HTTP requests for data from the browser. But the stream seems erratic, with a lot of characters interspersed between the HTTP requests. The request is there, but with just too much junk in between to recognize it. Any thoughts on what I can try to clean it up? :?
My guess is that “junk” is an ip and tcp headers. Am i wrong?
Oops - noticed I created a new topic rather than post to the existing WiFly section. Will ask this to be moved or re-moved :oops:
If that is the case I assume it would be the WiFly firmware that has a problem as the AVR does not deal with the frames, it just receives a serial stream back.
luwii:
Specifically, I’m trying to parse the HTTP requests for data from the browser. But the stream seems erratic, with a lot of characters interspersed between the HTTP requests. The request is there, but with just too much junk in between to recognize it.
You’ll need to be more specific on what counts as “junk”–one person’s junk is another one’s treasure.
Can you include the data you’re getting in a post?
And, no, nothing that’s getting returned should be at the IP or TCP level.
–Philip;
luwii:
Will ask this to be moved or re-moved :oops:
I think your post is fine right here!
-Bill
I think I identified the problem, well sort of. It’s something to to with framing and printing to the Terminal, not that WiFly data. If I put a lot of Serial.println statements before printing out the serial buffer on a per character basis then the data is clean!
This one caught me off guard as I tried various methods to print it out, and had some Serial.println statements before printing anything in any case.
At least I can carry on!
Now I have the real reason! The Serial.println caused a delay which made the code work. The real issue was I was reading the incoming data stream quicker than the buffer got filled up. Therefore filling my variable with the returned error that I did not handle. To be more specific:
The web server code has a (client.connected() && client.available()) check, and then within that block a c=client.read(); It’s important to check that client .read() does not return -1. in a loop like this. If it does, just wait a little bit and try again. Couple of milliseconds should do the trick.
Hi,
Thanks for taking the time to update us on this–it really makes a difference when people let everyone know how they solved their problems!
luwii:
The Serial.println caused a delay which made the code work.
Yeah, I’ve been caught by this type of thing in both directions–either a delay making code work or making it not work, which is why “print” debugging is not the height of debugging tools.
So this suggests the junk characters you were seeing were the ASCII character 255 (-1 as a byte value) which might appear as a block or a “y” with two dots above it or: “ÿ” or similar. It can be helpful when debugging single characters to display both the character and the value separately.
The web server code has a (client.connected() && client.available()) check, and then within that block a c=client.read(); It’s important to check that client .read() does not return -1. in a loop like this. If it does, just wait a little bit and try again. Couple of milliseconds should do the trick.
This is web server code that you’ve written yourself not based on one of the Ethernet or WiFly examples? The approach used in these examples to avoid the situation you encountered is to use something like this:
while (client.connected()) {
if (client.available()) {
char c = client.read();
// Handle just one character here.
}
}
If you check to see how many characters are available (the actual value returned from the available() call) then you can handle multiple characters at one time. If available() evaluates as true then you should never get -1 from a single call to read() so you shouldn’t need to check for it within a loop of this style.
Thanks again for letting us know the solution–all the best for the rest of your project.
–Philip;