If I check the device with curl, the particle cloud function setsleep was successfully registered.
curl "https://api.spark.io/v1/devices/3c0043001547343433313338?access_token=TOKEN"
{
"id": "3c0043001547343433313338",
"name": "MAJOR-101-MINOR-110",
"last_app": null,
"last_ip_address": "192.42.83.150",
"last_heard": "2016-12-20T22:30:09.124Z",
"product_id": 6,
"connected": true,
"platform_id": 6,
"cellular": false,
"status": "normal",
"current_build_target": "0.6.0",
"variables": {},
"functions": [
"setsleep",
"setbt"
],
"cc3000_patch_version": "wl0: Nov 7 2014 16:03:45 version 5.90.230.12 FWID 01-ca525900"
}
If I try to access the function with curl, it succeeds.
curl https://api.particle.io/v1/devices/3c0043001547343433313338/setsleep -d access_token=TOKEN -d "args=120"
{
"id": "3c0043001547343433313338",
"last_app": "",
"connected": true,
"return_value": 0
}
But if I try to access the function with nodejs particle.callFunction() , I get a function not found error.
var func = particle.callFunction({
deviceId: "3c0043001547343433313338",
name: "setsleep",
argument: 120,
auth: access_token });
func.then(
function (data) {
console.log('setsleep called successfully ', data.body.return_value);
}, function (err) {
console.log('error on setsleep: ', err);
});
Output:
error on setsleep : { statusCode: 404,
errorDescription: 'HTTP error 404 from /v1/devices/3c0043001547343433313338/setsleep',
error:
{ [Error: Not Found]
original: null,
response:
{ domain: null,
_events: {},
_maxListeners: 10,
res: [Object],
request: [Object],
req: [Object],
links: {},
text: '{\n "ok": false,\n "error": "Function setsleep not found"\n}',
body: [Object],
files: {},
buffered: true,
headers: [Object],
header: [Object],
statusCode: 404,
status: 404,
statusType: 4,
info: false,
ok: false,
redirect: false,
clientError: true,
serverError: false,
error: [Object],
accepted: false,
noContent: false,
badRequest: false,
unauthorized: false,
notAcceptable: false,
forbidden: false,
notFound: true,
charset: 'utf-8',
type: 'application/json',
setEncoding: [Function],
redirects: [] },
status: 404 },
body: { ok: false, error: 'Function setsleep not found' } }
The function is registered with the following code (simplified)
STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));
SYSTEM_MODE(SEMI_AUTOMATIC);
retained int SLEEP_TIME = 86400;
int set_SLEEP(String sleep) {
SLEEP_TIME = atoi(sleep);
return 0;
}
setup() {
Particle.function("setsleep", set_SLEEP);
Particle.connect();
}
This was working fine for a good two months or so. Since I don’t believe I made any changes, then the date might be notable; It started failing on Nov 29. Node version 0.10.46, particle-api-js version 5.3.0
[Mod Edit @harrisonhjones: Formatting]