- Years ago I first added simple web server functionality to serve up hardcoded pages (generated dynamically). You have to enable this in the webserver tab page in options.
-Around the same time I added a 'Custom Web' functionality to (additionally) serve up real files stored in the CustomWeb subdirectory. Simple way to transfer files but did not make available much x10 logic to put into custom web pages. To enable this Custom Web logic you needed to click an additional 'Enable Custom Web' checkbox in WebServer tab of options.
Fast Forward to now :
In order to open up x10dispatcher for (somewhat) serious web development I needed to clean up the internals of how files were served up. So I did and additionally I serve up some new JSON webservices as a mean for web developers to get access to x10dispatcher data/statistics which they can present however they want though their own web designs. If you don't know basic web programming (HTML/JavaScript) you might not be interested in this functionality, but if all you know is web programming and want to join in the x10 hacking this might be a good way to do so.
JSON is similar to XML with different syntax/structure... AJAX works with JSON to make data requests from javascript without reloading the webpage... which makes for dynamic webpages which can refresh data without losing context or reloading.
There are TONS of third party javascript libraries out there that can do anything from DataGrids, Image Carousels, Charting (jqplot, d3.js), and even 3d rendering of data with WebGL (using three.js).
The specifics of what I did add to 4.0.0 Custom Web is :
- Supporting subdirectories for serving up javascript libraries which have their own folder structure.
- Fixed Mime Types and response codes to 'play better' with what ajax expects (as well as what browsers themselves expect)... CSS;JS;XML;SVG;JPG;PNG any many other popular media (MP4;AVI;MP3;MOV;etc) and other formats (XLS,DOC,ZIP,RTF) all return the proper mime type.
- Fixed Response codes which browsers/ajax expect as well as content length.
With that functionality established, I added some JSON webservices so I can get access to x10 activity and display in a web page. These web services are :
/status.json : making an ajax request for status.json returns a javascript object containing arm status, alertsRaised flag, whether email is configured, twitter configured, twitter ping configured, whether image panel is enabled and Boolean flags for image1exists, image2exists (and 3 and 4)... images are still requested using /image1.jpg (or 2,3,4)
/alertlog.json returns an object with 'Alerts' property which is an array of objects, each representing a raised alert.. these alert objects contain 'AlertTime (datetime), AlertType (x10, poweralert, webalert), Description, Sent Email flag, Sent Twitter flag.
/alertlog-jqgrid.json : same as above but formatted for consumption using jqgrid open source data grid (my downloadable example demos this)
/eventlog.json : returns an object with 'Events' property which is an array of raw event history. Each event contains Transport, Transport Code, Device, Command, EventDateTime, AlertDescription (if triggers are defined it will display that description)
/eventlog-jqgrid.json : same as above but formatted for consumption using jqgrid.
/vars.json : x10dispatch variables designed specifically so a user (via web calls) can store and retrieve variables... any external program/script might read a digital thermometer (or whatever data acquisition they want) and call /serviariable.htm?Varname=VarValue to 'push' variable values into x10dispatcher which I would display in the web server... or NOW into your page. This JSON service returns 'Variables' array of objects with 'Name' and 'Value' properties (name might be 'temperature' and value might be '75'). x10 dispatcher in this mechanism is really just carrying around your variables, theres no logic that I do with these variables other than give them back to you (there are also commands available from the 'remote commands' tab on the main screen type help to play with)
Whew probably more than you wanted but pretty comprehensive in case I need to copy/paste later
I may improve this to send plc or other dispatch functionality in the future if anyone wants to web develop with this functionality.
Once I am confident about the 4.0.0 changes and status of the main code base I will probably improve my custom web demo site. The demo site could be prettier and I should add timers to refresh automatically. This demo site is a separate download available (zip file) from codeplex which you extract into the customweb subdirectory of x10dispatcher.