Go Down

Topic: Running CURL - Post method to Thingspeak (Read 17820 times) previous topic - next topic

AMMAS

Hey guys, I have been researching and I am trying to build a function that posts the output of a sensor to thingspeak on the Arduino Yun.

Here is my code so far, but I am getting no success, unfortunately. After looking up on the internet, everywhere I can, this is what I came up with.

Code: [Select]
void postToThingSpeak(int value) {
  Process p;
  String cmd = "curl -d 'key=XXXXXXXXXXXXXXXXX&field1=";
  cmd = cmd + value;
  cmd = cmd + "' -k http://api.thingspeak.com/update";
  p.runShellCommand(cmd);
  Serial.println(cmd);

  // do nothing until the process finishes, so you get the whole output:
  while(p.running());
}


PS: I took the cmd after it was printed, and ran it in terminal and it worked perfectly. For some reason it's not working on the Arduino Yun though.

Any assistance would be appreciated, thank you very much!

christop

I would try something like the following rather than running curl through a shell (which can be tricky sometimes to get right with quotes and such):

Code: [Select]

p.begin("curl");
p.addParameter("-d");
p.addParameter(String("key=XXXXXXXXXXXXXXXXX&field1=") + String(value));
p.addParameter("-k");
p.addParameter("http://api.thingspeak.com/update");
p.run();


I'd also read the output from the process (using p.read() after it's finished, until p.read() returns -1) and print it out to Serial so you can see the server's response, in case there's some kind of error.

Go Up