I want to execute a curl command from a Particle function.
I have the below code, but it does not compile. Any help would be highly appreciated.
// -----------------------------------
void setup()
{
Particle.function("DSon",dsOn);
Particle.function("DSoff",dsOff);
}
void loop()
{
// Nothing to do here
}
int dsOn(String command) {
Process proc = Process::run("curl http://localhost:80/myapp/mediaplayer/setStandbyMode?value=false");
proc.wait();
}
int dsOff(String command) {
Process proc = Process::run("curl http://localhost:80/myapp/mediaplayer/setStandbyMode?value=true");
proc.wait();
}
tester.cpp: In function 'int dsOn(String)':
tester.cpp:32:5: error: 'Process' was not declared in this scope
^
tester.cpp:32:13: error: expected ';' before 'proc'
^
tester.cpp:33:5: error: 'proc' was not declared in this scope
void loop()
^
While prototyping or early declaration is good practice, that statement is not 100% true.
The Wiring preprocessor will do the prototyping for you when cloud building an .ino file
I’ve seen your post about the struct parameter which left me puzzled as well, but in above case that shouldn’t be a problem.
However AFAIK, @jvanier had tweaked the preprocessor not too long ago to cause less hassle with “one-line if() ... else blocks” and these ridiculous blank-line-or-not trip-ups.
Maybe that might be a side-effect of that.
Your code in the opening post is missing the return instructions in the functions that are supposed to return an int.
But actually you should not “wait” in a Particle.function() callback - neither by using delay() nor by proc.wait() (unless you’ll be sure to return from the callback within 3sec).
But actually you should not "wait" in a Particle.function() callback - neither by using delay() nor by proc.wait() (unless you'll be sure to return from the callback within 3sec).
Yes, I can see why that is.
I actually copied the docs from the reference pages:
// SYNTAX
process.wait();
// EXAMPLE USAGE
// Run a Javascript program
Process proc = Process::run("node /home/pi/update.js");
proc.wait();