I’m using the npm particle-api-js v. 7.0.1. I have a function on my device, set_tset
, which sets a temperature setpoint, and then returns the value if successfully set. I also have get_tset
which returns that value from the device.
volatile double tset = 42; // default value, should be overridden
...
void setup() {
Particle.function("set_tset", set_tset);
Particle.function("get_tset", get_tset);
...
}
int set_tset(String command) {
String s = "";
Particle.publish("debug", s.format("API called set_tset: " + command));
float x = -1;
x = atof(command);
if (x > 0) {
tset = x;
}
return (int) x;
}
int get_tset(String command ) {
String s = "";
Particle.publish("debug", s.format("API called get_tset: |%3.3f| ", tset));
return (int) tset;
}
This function works fine with curl,
curl -X POST
https://api.particle.io/v1/devices/$dev/set_tset?access_token=$tok
-d arg="667"
successfully sets the variable on the device. However, in the JS API, using particle.callFunction
,
let config = {deviceId: this.devID, name: "set_tset", argument: arg,
auth: this.access_token};
particle.callFunction(config).then(...)
I get a 404 with this response:
{"ok":false,"error":"Function set_tset not found"}
Curiously, if I use callFunction
with no data argument passed, it succeeds with response:
{"id":"3b0024001247353236343033","last_app":"","connected":true,"return_value":0}
I get a confirmation from the console that the function was successfully called (with no argument). The function is definitely there, as calling it with empty argument works fine.