Hi,
For a uni task, I have to connect some LEDs to an Argon and create a webpage with buttons to turn them on/off. I got to the point where I could open command prompt and run the below command. It works and command prompt outputs the correct return value.
curl https://api.particle.io/v1/devices/device_id/toggle_led \ -d access_token=token \ -d "args=blue"
After that I made the webpage with some javascript, folliowing the callFunction part of this document. I can turn the LEDs on and off but I can’t get the return value. The document says that data.return_value
is the returned value, but for me it’s undefined when I try to log it to the console.
Here is my javascript code. I’d appreciate any help. I had var Particle = require('particle-api-js');
at the top of the function (cos it’s in the doc) but the console said ‘require is not defined’, so I removed it.
function toggle_led(colour)
{
var particle = new Particle();
var function_ptr = particle.callFunction({ deviceId: 'device_id', name: 'toggle_led', argument: colour, auth: 'auth'});
function_ptr.then(
function(data)
{
console.log('Function called succesfully:', data.return_value);
},
function(error)
{
console.log('An error occurred:', error);
}
);
}