Go Down

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


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";

  // do nothing until the process finishes, so you get the whole output:

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!


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.addParameter(String("key=XXXXXXXXXXXXXXXXX&field1=") + String(value));

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