Closed nheffronneuhold closed 6 years ago
I've discussed this with @cmaglie, client.flush()
is only intended to flush the transmit buffer and not the receive.
I'm not sure if this is something you have control over, but the documentation on the Arduino site makes it sound as if it clears the receive buffer (by saying "Discard any bytes that have been written to the client but not yet read."). I think it would be helpful to future users if it specified that it clears only the transmit buffer.
https://www.arduino.cc/en/Reference/WiFi101ClientFlush
On a separate note, do you have any idea why
while (client.available()) { client.read(); }
does not seem to be clearing the receive buffer either?
I think I may have solved it by adding a 10 millisecond delay within the loop like this
while (client.available()) { client.read(); delay(10); }
I don't know why that works while putting a delay before the loop (which I thought would allow all the data to flow into the buffer) doesn't, but I'm hoping someone with a similar issue in the future can find this.
I'm not sure if this is something you have control over, but the documentation on the Arduino site makes it sound as if it clears the receive buffer (by saying "Discard any bytes that have been written to the client but not yet read."). I think it would be helpful to future users if it specified that it clears only the transmit buffer.
@akash73 @simonepda can we please update the documentation to reflect this?
I don't know why that works while putting a delay before the loop (which I thought would allow all the data to flow into the buffer) doesn't, but I'm hoping someone with a similar issue in the future can find this.
@nheffronneuhold client.available()
can return 0 after a client.read()
if a data chunk is not received or buffered elsewhere.
Stream's private timedRead()
method might give you another idea on how to handle this: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Stream.cpp#L31-L40
I am trying to write a program that will pull and parse aviation weather data (XML), and am having issues with the parsing. I started with the WifiWebClientRepeating example and only made small changes to get it to connect via SSL, but when reading the data client.flush() does not seem to be doing anything. The XML comes back with several of the same nodes, and I'm trying to gather only the data from the first one.
Sample XML Data: https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=KORD&hoursBeforeNow=5
I'll put the full program at the end, but here is the code I'm using to parse it:
It parses the text I want, but then instead of flushing all the rest of the data, it goes through the while loop 4 or 5 more times (depending on how many nodes are returned) and parses all of those too. I have tried changing the delay (which I assume is necessary to let all the data come in) and it has no affect. I have also tried to following:
and it causes it to parse exactly one less node, regardless of the delay value. Any help would be highly appreciated. Full program: