I know that I can get a description back of any sendHubCommand () call I make using subscribed event lanResponseHandler(evt) but it does not tell me whtreher the call was successful. The app I use calls an external app via sendHubCommand and I would like to know whether the app actually received the call. For example, the external app is not running (or stuck in a loop) and my ST app does sendHubCommand. I would like to get back a status indicating the target app wasnt available to accept the command. Is this possible??
You need to subscribe to the responses. See this thread but it’s been problematic for people to get working.
Yes, I had already read that and implemented the suggestions. My needs are pretty straightforward. I simply want either a “Success” or “Fail” (like) response. Currently, I get a response only if the last command actually reached its target, in my case, EventGhost (EG). If for some reason EG or the LAN is down, I get nothing. Hence I came up with this interim solution:
// Called before/after each sendHubCommand() call
def runNotifyAt() {
unschedule()
state.msgSent=1 // yes. sendHubCommand was just called
state.lastResult=0 // Dont yet know if it was sucessful
def msTimeout=now() + cmdResponseDelay * 1000 // Wait for a response. Default 5 seconds or 5000 ms
def date = new Date(msTimeout)
runOnce(date, hubCommandResult)
}
def hubCommandResult() {
log.debug "The result of last Command= " + state.lastResult // either 0=fail, 1=success
if (state.lastResult==0) { // Msg failed
state.errorCount++
if (state.errorCount >= 3 && state.sendPushCount < 5) { // At least 3 errors in a row occurred and less than 5 sendPush() were sent
sendPush("EventGhost is not reponding to commands")
state.sendPushCount++
}
}
state.msgSent=0 // Clear last msg sent flag
}
def lanResponseHandler(evt) {
if (state.msgSent==1) { // A previous call to sendHubCommand is true
log.debug "SUCCESS: SendHub Message was sent/received"
state.lastResult=1 // SUCCESS
state.sendPushCount=0 // Reset the number of sendpush (error) messages that have been sent.
state.errorCount=0 // Reset the times sendHubCommand failed
}
state.msgSent=0
}