I am developing a web app with node.js.
I am having a problem calling function. When I call a function in the cloud, which just turns on led D7, in the cmd it is said that the fucntion was called properly, but the led does not turn on.
Here is my code with jade.js using express as framewrok:
And the sketch in the particle device:
I may be misunderstanding your environment, but when I call a function using the particle-api-js from node.js, I use a
particle.callFunction which takes an object containing the device ID, function, arguments and authentication token and returns a promise.
var on = particle.callFunction(...) as you’ve said but when need to call the function I use
Or at least I undertand that this is the way it should be done from the example in the reference page:
The only think I am doing in a different way is leaving tha argument empty, since the cloud function does not use it.
I don’t think you can use it like that. The particle.callFunction() returns a Promise. The code actually starts the operation at the point you call particle.callFunction(), not when you execute the then(). The example is misleading because fnPr makes it seem like a C function pointer, but it doesn’t really work like that.
Instead of using the variable
on, try moving the actual particle.callFunction() call where the
Now it is working.
Just for coding style:
Your functions are declared to return an
int so you should add a
return statement that actually does return an