Go Down

Topic: Problem reading the result of a Process (Bridge Library, Arduino YUN) (Read 2617 times) previous topic - next topic

Roque Campos

Dear Friends,

I'm using the Process class of the Bridge library to make a curl request and trying to read the result in a String Variable. My code is like the folowing;

Code: [Select]
Process p;
p.runShellCommand(curl_command);

while(p.running());  //Wait
  String result="";
  while (p.available()>0) {
   char c=p.read();
   result=result +c;
   Serial.print (c);
  }



The result of the curl command is a json string:

[{"id":"8","d":"2013-10-19 11:58:24","c":"roro","m":"on","com":"0","date_com":"0000-00-00 00:00:00"}]

The Rest service is working well (I tried the curl command from the linino command line).

The problem is that the while loop never ends. It reads, more or less

[{"id":"8","d":"2013-10-19 11:58:24","c":"roro","m":"on","com":"0","date_com... and then, a lot of strange ascii characters.

I taked the way of reading a Process result from the ShellCommand example. What I'm doing wrong?

Thanks in advance.

R.

PaulS

The art of getting good answers lies in asking good questions.

Roque Campos

Sorry about that, I thought that this was the correct subforum.

After a lot of tests, I managed to solve it myself. The problem is that the Json response is too long. If I modify the json and only return two fields, It works well.

Maybe a moderator can move this to te yun subforum. Maybe it's usefull for someone else.

Thanks.

federicofissore

I think you've hit a bug of the Bridge we've already fixed and that will be part of version 1.5.5 of the IDE. Try downloading a nightly version from http://arduino.cc/en/Main/Software#toc4, restore your json and retry

Roque Campos

Thank you for your answer. I followed your advice without success. But I think I have a clue. I called a wrong url by mistake, that returned the following result:

<h1>Not Found</h1>The requested URL /rest/do.php was not found on this server.


This response is a relatively long compared with my json. And with this response it works well. Then I suppose that the problem is inside the process class executing the curl command and waiting for the response.

I will try another approach to query my  mysql server and obtain the data while this problem persists.

Thank you again for your answer.

Go Up