process run does not return

Hi everyone,

I am currently trying to send a simple post request via curl on my arduino yun

The problem is that the process.run function simply does not return, the request execute succesfully, as i can see that the data has been send to the API, but then nothing.
On the serial window, the only thing i can see is the “a” that i output before the line, and then it blocks here.

Does any one have an idea ?

Thanks in advance, here is the code :

#include <Bridge.h>

void setup() {
  Bridge.begin();
  Serial.begin(115200);
}

void loop() {
  Process p;
  String startString;

  p.begin("curl");
  p.addParameter("-H");
  p.addParameter("Content-type:application/json");
  p.addParameter("-X");
  p.addParameter("POST");
  p.addParameter("-d");
  p.addParameter("{\"hardware_id\":\"1\",\"hardware_name\":\"TEST#1\",\"value\":\"1\",\"type_value\":\"CO\"}");
  p.addParameter("http://xxxx.com/xxx.php/xxx/xxx");
  Serial.println('a');
  p.run(); 
  Serial.println('b');
  delay(5000);
}

have a good day !

Hi, I don't use the run() anymore.

  p.runShellCommand(F( "curl -H Content-type-application/json -X POST -d {\"hardware_id\":\"1\",\"hardware_name\":\"TEST#1\",\"value\":\"1\",\"type_value\":\"CO\"} http://xxxx.com/xxx.php/xxx/xxx"));

  while(p.available() > 0)
  {
    char c = p.read();
    SerialUSB.print( c);
  }
  SerialUSB.println();

I have never tried such a long command with runShellCommand.

Hey Koepel, thanks for the answer.

It does the same thing with the command :

 p.runShellCommand(F( "curl -H Content-type:application/json -X POST -d '{\"hardware_id\":\"1\",\"hardware_name\":\"TEST#1\",\"value\":\"1\",\"type_value\":\"CO\"}'  http://xxxx.com/xxx.php/xxx/xxx"));

the api does receive the data, but it stops after the command :(

when i look at the logs from the api, the body that is returned from the request is pretty huge, could it have something to do with that ?

Hi, I've found the solution, the return from the API was indeed to big, so i had to remove the body, now it works as expected. I saw a post on the forum talking about that (http://forum.arduino.cc/index.php?topic=319855.0), i tried to update the bridge library but it changed nothing.

Hope it will help someone, one day.

If you have a huge response, then yes, I suppose it is likely for the process output buffer to fill up and stall things until you can read from the buffer. But with the .run() command, you will never return to where you can read the output.

A solution may be to use the .runAsynchronously() version. That will return to the script, and where you can use .available() to check for data ready to be read, and then read and process or discard the data. Keep doing this as long as .running() returns true. Once .running() returns false, the process is done, and you will be at the point where you would be after the .run() command returns.

Or, write a script on the Linux side to call the curl command and do whatever processing you want on the returned output, and just return the digested part of the output that you want (if any) to the sketch.