client.getAsynchronously() doesn't seem to get anything client.get() works.

Hi,

just wondered if anyone can shed some light on this. On the Arduino Yun I am trying to get some data back from ThingSpeaks TalkBack App.

I sent a URL and expect to read back a command. It works fine with get, but get slows down my code as it waits for the response, so I want to use client.getAsynchronously(). When I try that I get nothing back. To check it wasn't my code I modified the example where it downloads the Arduino ASCII art, and I get the same result. with client.get() it works with client.getAsynchronously, I get nothing.

Am I doing something stupid?

#include <Bridge.h>
#include <HttpClient.h>
#include <Console.h>

void setup()
{
    Bridge.begin();
    Console.begin();
}

void loop() 
{
      HttpClient client;
      client.getAsynchronously("http://arduino.cc/asciilogo.txt");
      while (client.available())
      {
              char c = client.read();
              Console.print(c);
      }
      delay(5000);
}

Unless that code is supposed to just illustrate a problem, I can't see any benefit in asynchronously requesting data so that can sit around for 5 seconds with your thumb up your xxx.

Typically, code like getAsynchronously() expects you to register a callback to be called when the data arrives. It is, typically, NOT a direct replacement for get().

Just to illustrate the problem, Modified from the bridge httpclient example so the delay(5000) is redundant. The problem I have is because the arduino reference for getasyncronously() points to get() on the site, I don't have any example code of how getasyncronously is supposed to work to begin playing with

Look at the source code. The HttpClient class derives from Process. The Process.run() method actually calls runAsynchronously() and then blocks until running() returns false.

Your code needs to check running() to determine when the process is complete. Then, it can read the data, using client.available() and client.read(), just like it does when using the get() method.

HttpClient client;

int intentos_ready = 0;

String url = "http://www.google.es";

client.getAsynchronously(url);

while (!client.ready()) {
intentos_ready++;
Serial3.print("esperando conexion "); Serial3.println(intentos_ready);
if (intentos_ready > 5){
intentos_ready = 0;
break;
}
delay(100);
}

if (client.available()) {

intentos_ready = 0;
}