Page 1 of 1

Plugin: Waiting for Device Status update

PostPosted: Sun Mar 21, 2010 8:03 pm
by Oliver
Hi,

I am putting together a plugin to control Indigo from the Cisco IP Phone Display using the XML SDK.

Any best practice on how I can ensure commands have been sent and the database updated after I use any of the device control functions ?

For example: cherrypy.server.indigoDb.DeviceTurnOn(cherrypy.server.indigoConn, device, cherrypy.request.remote.ip)
After calling this function, I refresh the webpage, but I still see the "old" values for the device states.
How can I wait with the page generation until the device has (or not) responded and Indigo has updated the database?

best regards,

Oliver.

Re: Plugin: Waiting for Device Status update

PostPosted: Mon Mar 22, 2010 7:15 am
by seanadams
The best solution is to have an asynchronous (ajaxy) interface where you can push device status updates down to the browser at any time - like how Indigo control pages work. Without this, you're not going to see updated device states that result from triggers, scheduled actions, or UI input by other means.

But to answer your question - yes, you could suspend delivery of the web response until you receive the expected status update. This should have a fairly short (eg 5 sec) timeout so the browser isn't hanging around forever in case of an error.

How to implement such a thing depends on how you are designing your client. To do it right you will need a proper event loop, with an async Indigo client and an async http server. I have a general solution for this sort of Indigo client in perl ( http://www.seanadams.com/ha/automogator/ ). Although I haven't tried to collect responses within the handling of an HTTP request as you're describing, it would be feasible.

Re: Plugin: Waiting for Device Status update

PostPosted: Mon Mar 22, 2010 7:54 am
by seanadams
Simpler solutions, such as fetching Restful URLs from Indigo could be done in the context of a cgi script...

Re: Plugin: Waiting for Device Status update

PostPosted: Fri Apr 02, 2010 2:10 pm
by Oliver
Hi Sean,

Thanks for your help! The client on the phone is not very flexible and not really html based but rather xml.

I ended up with the pragmatic solution of just using "delay" of 2 seconds before refreshing the page to the phone.

best regards,

Ollie.

Re: Plugin: Waiting for Device Status update

PostPosted: Fri Apr 02, 2010 5:45 pm
by seanadams
I misunderstood - thought you were writing a separate program to do this and did not realize you were doing this all in the phone. Pretty cool!