How do I properly detect if my Particle Photon is offline?
I currently setup a function that gets called every 15 minutes that pings the Particle Photon.
It works fine when the Photon is online but fails when it is offline.
private getStatus() {
def params = [
uri: "https://api.particle.io/v1/devices/${deviceId}/status?access_token=${token}"
]
asynchttp_v1.get(processData, params)
log.info("getStatus")
}
def processData(response, data) {
log.info("processData")
if (response.data.hasError()) {
log.info("Test.")
}
// More code.
}
The Particle Photon outputs:
{"error":"Timed out."}
When offline and SmartThings outputs:
error java.lang.IllegalArgumentException: Failed to complete. Message was: Read timeout to api.particle.io/34.226.167.93:443 of 20000 ms @line 93 (processData)
I have tried reading Particle Photon’s response.
private getStatus() {
def params = [
uri: "https://api.particle.io/v1/devices/${deviceId}/status?access_token=${token}"
]
asynchttp_v1.get(processData, params)
log.info("getStatus")
}
def processData(response, data) {
log.info("processData")
def results = new groovy.json.JsonSlurper().parseText(response.data)
if (results.error) {
log.info("Test.")
}
// More code.
}
Which results in a similar error in the SmartThings Logs.