Hey guys,
I have been trying to find a way to check whether a core is online at a specific moment (not scheduled), I did find a workaround, but the documentation says that it would return 404 if the CORE is not connected to the cloud but with the API calls I have only received it if an ONLINE core does not have the requested function. In addition, the API is returning codes which I believe do not make sense nor are very consistent.
Offline core:
GET devices/{deviceid}/variable
: 408 Timeout
: {āerrorā: āTimed out.ā}
POST devices/{deviceid}/function
: 200 OK
: {āerrorā: āTimed out.ā}
GET /devices/{deviceid}
: 200 OK
: {āidā: ā{deviceid}ā,ānameā: āSpark coreā,āvariablesā: null,āfunctionsā: null}
Online core:
GET devices/{deviceid}/variable
: 200 OK
: {ācmdā: āVarReturnā,ānameā: ātestā,āerrorā: āVariable not foundā,ācoreInfoā: {ālast_appā: āā,ālast_heardā: ā2014-02-10T15:29:19.534Zā,āconnectedā: true,ādeviceIDā: ā{deviceid}ā}}
POST devices/{deviceid}/function
: 404 Not Found
: {error: āFunction not foundā}
GET /devices/{deviceid}
: 200 OK
: {āidā: ā{deviceid}ā,ānameā: āSpark coreā,āvariablesā: null,āfunctionsā: null}
^^^^^ Last one could change if any variable or functions are exposed.
Yes, I could create a function and check for the āconnected: trueā part, but there are some problems with this:
- I have to send an already existing exposed function which I have to know before hand (which might change from core to core) and have to code it so itās ignored because itās just an online check and I want no action to be done.
- I can expose a brand new function just to return 1 which effectively would reduce my exposed functions by 1 and of course, have to take the time to put it every time.
I guess meanwhile I could try sending a GET variable or POST function and check the Json for timeout.
My recommendations for the spark team:
- I believe it would be awesome to have the āconnected: {state}ā in the GET /devices/{deviceid}
- If possible have the last_heard in the GET /devices/{deviceid} as well (in case this is saved after the core is disconnected)
- Return 404 (or 408?) in GET /devices/{deviceid} if core is offline
- Return a consistent code of 408 or 404 when doing /variable and /function on offline cores
- Return 400 on a non exposed /variable and /function
Thanks for your time and for reading my post!