It occurred to me that there is a simpler approach you can take with this. Rather than format the response into XML, you can simply output HTML and dump that into a label on your remote control using Ajax. I've put together a sample for you:
The HTML web page:
<html>
<head>
<title>Remote Control With Feedback</title>
<link href="/style/style.css" type="text/css" rel="stylesheet" media="screen">
</head>
<script src="/scripts/remotecontrol.js"></script>
<script>
function load() {
Ajax = new Ajax();
Ajax.URL = "remotefeedback.lsp";
Ajax.Interval = 3000;
Ajax.Feedback = MyFeedback;
Ajax.Status = MyStatus;
Ajax.Refresh();
}
function MyFeedback(feedback) {
Connection.innerHTML = feedback;
}
function MyStatus(status) {
Feedback.innerHTML = status;
}
</script>
<body onLoad="load();">
<div id="Connection"></div>
<div id="Feedback"></div>
</body>
</html>
And the remotecontrol.js (ajax script):
function Ajax() {
var timeoutID;
var param;
var polling;
var ImagePath = '';
var Interval = 3000;
var xmlhttp = CreateXMLHttpRequest();
var URL = "feedback.lsp";
function CreateXMLHttpRequest() {
if (window.ActiveXObject) {return new ActiveXObject("Microsoft.XMLHTTP"); }
if (window.XMLHttpRequest) {return new XMLHttpRequest(); }
return null;
}
this.Start = function() {
if(!polling)
polling = setTimeout("Ajax.Refresh()", Ajax.Interval);
}
this.Stop = function() {
clearTimeout(polling);
polling = null;
Ajax.Feedback("<font color=red>Disconnected...</font>");
}
this.Refresh = function() {
if(xmlhttp) {
if(!this.CallInProgress(xmlhttp)) {
xmlhttp.open("GET", Ajax.URL, true);
timeoutID = setTimeout('Ajax.OnTimeout()', 5000);
xmlhttp.onreadystatechange = this.ChipmunkResponse;
xmlhttp.send(null);
} else {
Ajax.Feedback("<font color=red>Slow Connection...</font>");
}
} else {
Ajax.Feedback("<font color=red>Disconnected...</font>");
}
polling = setTimeout("Ajax.Refresh()", Ajax.Interval);
}
this.Command = function(query) {
if(xmlhttp) {
if(!this.CallInProgress(xmlhttp)) {
xmlhttp.open("GET", Ajax.URL+"?Action="+query, true);
timeoutID = setTimeout('Ajax.OnTimeout()', 5000);
xmlhttp.onreadystatechange = this.ChipmunkResponse;
xmlhttp.send(null);
} else {
Ajax.Feedback("<font color=red>Slow Connection...</font>");
}
} else {
Ajax.Feedback("<font color=red>Disconnected...</font>");
}
}
this.OnTimeout = function() {
xmlhttp.abort();
this.Feedback('<font color=red>Timed Out...</font>');
}
this.ChipmunkResponse = function() {
if(xmlhttp.readyState == 4) {
window.clearTimeout(timeoutID);
if (xmlhttp.status==200) {
if(polling != null)
Ajax.Feedback("<font color=green>Connected...</font>");
Ajax.Status(xmlhttp.responseText);
} else {
Ajax.Feedback("<font color=red>Connection Lost...</font>");
}
}
}
this.CallInProgress = function(xmlhttp) {
if(xmlhttp) {
switch (xmlhttp.readyState) {
case 1:
case 2:
case 3: return true;
default: return false;
}
} else {
return false;
}
}
this.Feedback = function(feedback) {}
this.Status = function(status) {}
this.Replace = function(str, old, repl) {
while((pos = str.indexOf(old)) > -1) {
str = str.substr(0, pos) + repl + str.substr(pos + old.length);
}
return str;
}
}
var Ajax;
And finally the remotefeedback.lsp page:
<%
Response:SetHeader('Logging', 'Omit');
Response:Write('<span>'..os.date()..'</span>')
Response:Write('<br>')
Response:Write('<span>'.._VERSION..'</span>')
%>
The os.date() Lua function returns the current date/time and _VERSION is a Lua global variable. Just modify the lsp and html pages to your needs. Place the lsp and html pages in the root directory and place remotecontrol.js in the scripts directory. You can adjust the refresh rate by setting the Ajax.Interval property. By default it refreshes the display every 3 seconds. The Response:SetHeader('Logging', 'Omit') line is to prevent the web server logging the request (otherwise the log will rapidly fill up).
You can download these files here:
http://www.chipmunkav.com/support/remotecontrol.zip
Shaun
Chipmunk AV Controller Founder