Go Down

Topic: Mega 2560 + WiShield - client.available() issues (Read 952 times) previous topic - next topic



When trying to run a simple get program, I ran into issues while trying to process the get request.
In a simple nested loop example, like this:
  while (client.available()) {
     char c = client.read();
The client.connected() evaluates as true, but the client.available() -which returns how many bytes I have available for reading- returns 0. Why do I not have any available space? Do I need to use an SD card?



Why do I not have any available space?

If connected() returns true, and available() returns 0, it means that the Arduino is waiting for the server to supply a response that can be read.

What are you connecting to? What GET request did you make? What response is that server/script returning?

The available() method says nothing about space.
The art of getting good answers lies in asking good questions.


servername is: char servername[]="www.arduino.cc"; 

  if (client.connect(servername, 80)) {
      // Make a HTTP request:
    client.println("GET /latest.txt HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");

    while(client.connected()) {
      while (client.available()) {
       // client.setTimeout(2000);
        char c = client.read();

I am just trying ot get the source from the page: http://www.arduino.cc/latest.txt


The Host, User-Agent, and Connection statements are not needed.

Do you have DNS enabled, outside that snippet? If not, you need to use IP addresses, not host names.
The art of getting good answers lies in asking good questions.


sorry, apparently there are just problems between the wifi shield and mac OSX. Tried it on a windows machine and it worked. Thanks

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131