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.