I can not seem to get on switch.on, swithch.off handlers to fire EVERY time when a change occurs. At the start I can turn on the virtual switch and the onHadler is called. Follow this by turning off the switch and the offHandler is called. After that anything is possible. Most of the time the handlers are not called immediately thereafter. Only way to get everything working again is to turn on then off then on again. Switching to off may cause the offHandler to be called but for certain the subsequent on will fail.
Here is the code
subscribe(theLight, "switch.on", onHandler)
subscribe(theLight, "switch.off", offHandler)
def onHandler(evt) {
log.info "Modem will be monitored every $theSeconds Seconds"
sendPush("Modem will be monitored every $theSeconds Seconds")
atomicState.doMonitor=true
runNotifyAt(now() + (theSeconds * 1000))
}
def offHandler(evt) {
log.info "Modem will be not be monitored"
sendPush("Modem will be not be monitored")
atomicState.doMonitor=false
}
def runNotifyAt(timeMs) {
def date = new Date(timeMs)
runOnce(date, checkEastlinkModem)
}
def checkEastlinkModem() {
if (atomicState.doMonitor == true) {
def url="http://xxxx.xxxx.xxx/xxx/xxx.html"
def theStatus=-1
try {
httpGet(url) {response ->
def cnt = 0
theStatus=response.status
}
}
catch(e) {
}
log.info "Current Modem Status Test Result = $theStatus"
runNotifyAt(now() + timeMS)
}
}
Does anyone see anything obviously wrong?