callFunction JS SDK

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.

1 Like

I use var on = particle.callFunction(...) as you’ve said but when need to call the function I use on.then(...).

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 then is.

1 Like

Many thanks.
Now it is working.

1 Like

Just for coding style:
Your functions are declared to return an int so you should add a return statement that actually does return an int.