Indigo Web Server plug-in architecture (alpha 1)

Posted on
Tue Oct 30, 2007 7:56 pm
matt (support) offline
Site Admin
User avatar
Posts: 20539
Joined: Jan 27, 2003
Location: Texas

Indigo Web Server plug-in architecture (alpha 1)

The public beta 6 of 3.0 includes the initial development of a plug-in architecture for the Indigo Web Server (IWS). This is not a plug-in architecture to add new hardware support or UI to Indigo, but is an architecture to allow for browser based plug-in pages. An additional plug-in architecture is under development for hooking into Indigo Server itself.

The IWS plug-in support enables you to more easily serve your own static and dynamic content via IWS. This content can access and control the Indigo database (ex: turn devices on/off), but it can also be used for non-Indigo purposes. The intention of this plug-in support is to provide a solution for 3rd parties and end-users to extend IWS's capability in a manner that can both be shared with others and can be preserved across Indigo updates.

For example, I created a plug-in that serves video image files from EvoCam. This allows me to use a single web server for both Indigo and serving video image files. I have another plug-in that I use as a home page, which contains bookmarks to sites I frequent and Indigo Control Pages.

Another good example would be a plug-in that serves control pages formatted for the iPhone and iPod Touch. Note: I have not started on such a plug-in yet, so have at it. :-)

Here is an example plug-in. To use it copy over the sample folder into the plugins directory:

/Library/Application Support/Perceptive Automation/Indigo 2/IndigoWebServer/plugins/

Next, we need to restart IWS so that the plug-in is loaded. To restart just IWS and not the entire Indigo Server you can access this URL on your server Mac:

http://127.0.0.1:8176/indigocommand?name=restart

Or, you can just stop and restart the entire Indigo Server.

You should then see in the Indigo Event Log that the plug-in was loaded and that some of the plugin's folder were made browser accessible:

Code: Select all
  WebServer          loaded plugin "Sample Plugin"
  WebServer          enabled browser access to plugin path "plugins/sample/static"


You can now access any image, HTML, and JS files in any of the pre-defined static plugin folders: css, js, images, video, static. For example, here is the path to access the static HTML file in the sample plug-in:

http://127.0.0.1:8176/sample/static/static_example.html

To serve dynamically created pages, you can extend the functionality inside the plug-in's reqhandler.py file. This requires some Python coding. The request handlers define functions that are called based on the URL path.

For example, this page is dynamically created by the "def index(self)" function inside reqhandler.py:

http://127.0.0.1:8176/sample/

And this page, which shows how to render a Cheetah template file, calls the function "def template_example(self)":

http://127.0.0.1:8176/sample/template_example/

Please read through the comments inside Sample plug-in's reqhandler.py file. As of right now, that is the best documentation we have.

Questions / Comments / Suggestions?

Regards,
Matt

TIP: I recommend using TextWrangler for editing the Python (.py) files. It is free and it does a good job with syntax coloring.

Posted on
Tue Oct 30, 2007 8:18 pm
dtich offline
Posts: 630
Joined: Sep 24, 2005

(No subject)

wow, you've been busy! a lot of adds in the new beta, very nice indeed. thx.

Posted on
Tue Oct 30, 2007 8:35 pm
dtich offline
Posts: 630
Joined: Sep 24, 2005

(No subject)

matt, i'm gettin:

Code: Select all
 Sent INSTEON       "av/bedroom amp" status request (received: 0)
  Sent INSTEON       "office/krell amp" status request (received: 100)
  Sent INSTEON       "office/exhaust fan" status request (received: 0)
  Sent (offline)     undefined status request
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  Client connected
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  Time/Date Action   _delayed_action_6
  Weather NOAA       Weather NOAA Script Started
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols


gonna do another restart..

Posted on
Wed Oct 31, 2007 6:46 am
matt (support) offline
Site Admin
User avatar
Posts: 20539
Joined: Jan 27, 2003
Location: Texas

(No subject)

Code: Select all
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  WebServer          internal server error "/_getupdatedcontrols" from 192.168.0.2
  ...

I think this was because the browser on your 192.168.0.2 Mac was using a cached older JavaScript file that passed some deprecated arguments to the web server in the latest beta. Clearing your browser cache or refreshing the page should fix it.

Regards,
Matt

Posted on
Wed Oct 31, 2007 9:52 am
dtich offline
Posts: 630
Joined: Sep 24, 2005

(No subject)

yep, it cleared up after restart. :roll:

Posted on
Wed Oct 31, 2007 10:40 am
MikeB offline
Posts: 32
Joined: Nov 16, 2006
Location: Cupertino, CA

Re: Indigo Web Server plug-in architecture (alpha 1)

Could you post a copy of the Evocam plug in ?

Thanks !

Mike

Posted on
Wed Oct 31, 2007 11:10 am
matt (support) offline
Site Admin
User avatar
Posts: 20539
Joined: Jan 27, 2003
Location: Texas

Re: Indigo Web Server plug-in architecture (alpha 1)

Sure. It is actually part of a custom MyHouse plug-in that has other custom functionality as well, but here are the parts for the EvoCam support. Inside the reqhandler.py file add a new URL handler function:

Code: Select all
   def cameras(self):
      tmpl = self._GetAndLockPluginTemplate('sample/templates/cameras.html')
      try:
         tmpl.requestFromPrism = self._IsRequestFromPrism()
         tmpl.useUniqueUrlToAvoidCache = self._UseUniqueUrlToAvoidCache()
         return tmpl.RenderTemplate()
      finally:
         tmpl.ReleaseLock();
   cameras.exposed = True



Then save a new cameras.html Cheetah template file into the plug-in's template folder:

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
      <title>Indigo Home Control Server</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   </head>
   <body>
      <div align="center">
         <img src="images/camera1_large.jpg" border="0" name="refreshTag" />
         <SCRIPT language="JavaScript" type="text/javascript">
         <!--
            var imageName = "images/camera1_large.jpg";
#if $requestFromPrism
            var refreshInterval = 120.0;         // throttle back to every 2 minutes if remote
#else
            var refreshInterval = 1.0;            // refresh interval in seconds
#end if
            function RefreshNow() {
               var cacheKiller = new Date();
               cacheKiller = "?nocache=" + cacheKiller.getTime();
               document.images["refreshTag"].src = imageName + cacheKiller;
               setTimeout("RefreshNow()", refreshInterval * 1000);
            }
            RefreshNow();
         -->
         </SCRIPT>
      </div>
   </body>
</html>


Last, I have EvoCam save out new JPG image files every second into the plug-ins image folder:

Code: Select all
plugins/sample/images/camera1_large.jpg


To access this you would then use something like:

Code: Select all
http://127.0.0.1:8176/sample/cameras

If you have multiple cameras you want to serve as individual pages, then you could modify the python cameras function to accept an argument via the URL. That argument could then be passed on to the Cheetah template to pick a specific image file.

This could be simpler by using just a static HTML page (no Cheetah template), but my upstream ISP connection couldn't keep up with refreshing the image every second (via Prism Reflector) whereas on my LAN that isn't a problem. I also don't want too much bandwidth being bounced off the GoPrism.com hosted server ($$).

The JS technique of refreshing the image could use some improvement. It works okay, but Safari will chew through memory if you leave the window open (Opera and FF handle it better) because of the unique URL used for each refresh. It clears it up once the window is closed, but can get pretty bogged down if you leave it open for a couple of hours.

Matt
Last edited by matt (support) on Fri Oct 03, 2008 2:57 pm, edited 1 time in total.

Posted on
Mon Dec 03, 2007 5:11 pm
Martijn Heeroma offline
Posts: 189
Joined: Oct 24, 2007

(No subject)

Nice work Matt

Posted on
Tue Dec 11, 2007 10:10 am
Empyrean offline
Posts: 20
Joined: Oct 28, 2006

Two questions...

Matt,

Do you think it would be possible to use this feature to integrate Indigo with Jott?

http://www.jott.com/developers/

Also, is there a way to use Indigo to proxy varies web sites running on different ports on the same machine. For instance, I could run SlimServer, WebJimbo, RemoteBuddy, etc. all acting like they are different hosts running on port 80 rather than all the other ports I need to keep running.

Thanks,
AJ

Posted on
Wed Dec 12, 2007 6:58 pm
matt (support) offline
Site Admin
User avatar
Posts: 20539
Joined: Jan 27, 2003
Location: Texas

Re: Two questions...

I definitely think that someone could write a Jott plug-in for the Indigo Web Server. It would be pretty straightforward, I believe.

I'm not sure how easy it would be to use the Indigo Web Server to proxy other web servers. I imagine it is possible, but a better approach would probably be to use OS X's built-in web server (Apache) and have it proxy everything else. I've never done it, but here are the instructions on how to run CherryPy behind Apache. The Indigo Web Server is built on top of CherryPy.

Regards,
Matt

Posted on
Wed Jun 25, 2008 7:58 pm
737SimGuy offline
Posts: 23
Joined: Oct 29, 2007

(No subject)

Is there any way to trap access to a static page within my plugin? I simply want to log when my static page is accessed.


Thanks!

James

Posted on
Wed Jun 25, 2008 10:06 pm
jay (support) offline
Site Admin
User avatar
Posts: 16778
Joined: Mar 19, 2008
Location: Austin, Texas

(No subject)

If you're talking about an IWS plugin that you built yourself logging to the file system, then yes, inside the plugin you can do pretty much whatever you want (as long as you have permission to the filesystem). If you're talking about a plugin that would log accesses to other IWS pages, then no, you can't. The plugin context is a simple single page context: it knows nothing except the request information that it got from the web server, not unlike a PHP or Perl script.

Having said that, I would guess that there's some way to configure cherrypy to log accesses if you wanted to dig around and figure it out... ;)

jay

Posted on
Wed Jun 25, 2008 10:11 pm
737SimGuy offline
Posts: 23
Joined: Oct 29, 2007

(No subject)

Well, I see how to do the dynamic traps, but nothing for a static page trap. Yes, this is a plugin I added. Any hints?

Thank you,

James

Posted on
Wed Jun 25, 2008 10:25 pm
jay (support) offline
Site Admin
User avatar
Posts: 16778
Joined: Mar 19, 2008
Location: Austin, Texas

(No subject)

Ah, now I get you: you want to log when the static content in one of the directories in YOUR plugin is accessed! Sorry, it's late... ;)

OK, so, if you use the directories that automatically serve static content (css, js, images, video, static), then no. HOWEVER, you can write your own static content handler, such that the path isn't one of those, then serve the content up yourself...

jay

Posted on
Sat Aug 23, 2008 3:26 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: Indigo Web Server plug-in architecture (alpha 1)

Hello, Matt-

I am in my 30-day trial of Indigo and I am feverishly testing whether or not it is right for my needs. One of the things I wanted to try was integration with my EvoCam server, so I tried the above. When I click the link to my camera from my control page, I get this message: "undefined page requested." I tried linking to the "template_example" instead as a test of my linking and it worked perfectly.

What should I look for to fix this? I have EvoCam providing the image as needed to the folder described.

Thanks!

Who is online

Users browsing this forum: No registered users and 1 guest