HubAction Failed Response

Hi,

I’m writing my own custom “presense sensor” to check that my server is up and running correctly, and notify me and perform actions if my server goes down. It currently works by polling the server and then parsing the result, if it receives a response it stores this in a local variable. When it next polls, it looks at the result of the previous poll to see if the variable was set, and if it was sets the device as “present”. The problem with this method is it takes two polls to get a present result, rather than just one.

The reason I built it this way was that after sending a HubAction to poll the server, the only response I could ever get was a successful one, not a failed one. So I would use the second poll call to see if the last one ever received a response, but it would be far more efficient if I could detect the failed HubAction.

Is this possible? Or is my workaround the best I can do?

Thanks

I wanted to be able to get immediate notifications if I lose power or my internet goes down so I added similar functionality to a device type I wrote.

When poll is called, my device handler does the following to get around the problem you described.

  1. Send command to the device when poll is called.

  2. Schedule method to run in 15 seconds that creates the “not present” event.

  3. When device responds, it unschedules the other method and creates the “present” event.

There’s probably a better way of doing this, but so far this method has been reliable for me and it sounds like you could do the same thing to ping the hub.

Ah, thanks. I did consider a timed response, but am new to the language and wasn’t sure if it supported timers and threads etc.

I’ll change to work like this now, much appreciated.

▼ Hide quoted text

@krlaframboise
Can you post an example of this code