passing parameter from browser to Indigo/AppleScript

Posted on
Thu Jul 05, 2007 11:46 pm
jsmorris offline
Posts: 17
Joined: Jul 01, 2007

passing parameter from browser to Indigo/AppleScript

When a button is clicked on a control page, I'd like to serve different control pages, depending upon which computer the page request came from, i.e. serve a page customized for that particular computer's location. Is there any way to pass a parameter from the browser back to the Indigo server and to an AppleScript that I could use to identify which machine generated the request? Thanks for any suggestions.

Jeff

Posted on
Fri Jul 06, 2007 8:17 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: passing parameter from browser to Indigo/AppleScript

Hi Jeff,

The easy solution would be to just duplicate your Control Pages and give them unique names, one for each computer. The downside to that will be any edits made to the pages will have to be done across all the pages.

The Indigo Web Server and templates could be hacked to do it without duplicating pages, but it would require a bit of work. The line you would want to edit in the template file is line # 8 (after the actionType == 1015 conditional) of this file:

/Library/Application Support/Perceptive Automation/Indigo 2/IndigoWebServer/templates/_pageelem.html

That is the line that generates (fills in) the URL for control page "on click" actions. The tricky part is then making that unique based on which browser is connected. For that you would probably have to pass in an HTTP variable in the URL, and then make sure that is available with the _pageelem.html template is generated. So each browser would have a unique URL argument like this:

http://127.0.0.1:8000/controlpage?name= ... livingRoom
http://127.0.0.1:8000/controlpage?name= ... rId=office
etc.

Hope that helps to get you started. As I mentioned at the top, duplicating the Control Pages would definitely be the easiest approach. :-)

Regards,
Matt

Posted on
Fri Jul 06, 2007 10:20 pm
jsmorris offline
Posts: 17
Joined: Jul 01, 2007

(No subject)

Hi Matt,

Thanks for the prompt help. I though of duplicate pages, but I expect to have four or five browser locations. That's a lot of work to change each of five pages for every minor change I want to make. Besides, the idea of doing it that way, instead of programatically, bothers me!

There's one thing I don't understand. When I first fire up the browser, I can type the browserId into the URL. However, all subsequent URLs are generated from the _pageelem.html template through clicks on the page. I'm not sure how it figures out which browserId to insert.

I assume the template generates the page on-the-fly when the browser requests it. Does the template have access to cookies? If so, I could modify the 1015 type in _pageelem.html to check for page=local, then use if/thens to generate the appropriate target URL, depending upon the cookie value (bedroom, office, etc.). Indigo doesn't need to create the cookies--I can do that with a php page--only read them.

Does this make sense, or am I missing something?

Thanks,
Jeff

P.S. Here's a typical "local" control page. I'm planning to use an internet tablet with a 3.5" x 2" screen. All tabs on each browser go the the same control page except for LOCAL, which goes to bedroom, office, etc., depending upon which browser/tablet is doing the calling.
Image

Posted on
Sun Jul 08, 2007 8:15 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

(No subject)

The template has access to any variables that are assigned to it in the python source before its renderTemplate() function is called. Try modifying line 362 of the file IndigWebServer/indigopy/indigoreqhandler.py from:
Code: Select all
def controlpage(self, name=None, serverStatus=None):

to:
Code: Select all
def controlpage(self, name=None, serverStatus=None, browserId="unknown"):

Next add this line after line 390 (right before renderTemplate() is called):
Code: Select all
tmpl.browserId = browserId

Lastly, you can modify the template file itself. Any argument you pass in the URL for the browserId should now be available for you to conditionally test. You'll have to stop and restart the IndigoServer (Indigo 2->Stop Server menu item) before the changes to the python file and template file to take. Hope that helps!

Regards,
Matt

Posted on
Mon Jul 09, 2007 5:57 am
jsmorris offline
Posts: 17
Joined: Jul 01, 2007

(No subject)

Matt,

Thanks for your help. I hadn't done any Python code before, so it took a little while to get some of the syntax right, even though it was only a few lines. The hacked server does exactly what I needed. I really appreciate the help--I never would have figured it out otherwise.

Jeff

Posted on
Mon Jul 09, 2007 9:48 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: iPhone causes USB data read errors

Hi Jeff,

Great -- glad you got it working. Be sure and make backup copies of the template and python files you modified. Future installs of Indigo may overwrite your changes, in which case you'll need to copy/paste them back in.

Regards,
Matt

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 17 guests