Author |
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: December 31 2004 at 03:48 | IP Logged
|
|
|
Hi all.
Am currently having a problem processing a PH global variable in a Java function.
Have included the barebones code to highlight my problem
========================================================
<html>
<head>
<title>Java Test</title>
<script language="javascript">
//Evaluate a formula
function f_formula(formula)
{ document.evalformula.formula.value = formula; document.evalformula.submit(); }
//Return and process Global Variables
function GetStatus()
{
var sResponse = f_formula('ph_getglobal_s(\'TESTGLOBAL\')');
//Have tried...
//document.frmStatus.tvstatus.value = f_formula('ph_getglobal_n(\'TESTGLOBAL\')');
//document.frmStatus.tvstatus.value = f_formula('ph_getglobal_s(\'TESTGLOBAL\')');
//To prove f_function... works from within GetStatus()
//f_formula('ph_setglobal_s(\'TESTGLOBAL\',\'10\')');
//The following 2 lines successfully returned a value
//var nResponse = 1;
//document.frmStatus.tvstatus.value = nResponse;
document.frmStatus.tvstatus.value = sResponse;
}
</script>
</head>
<form method="post" action="/ph-cgi/evalformula" name="evalformula" target="blankframe">
<input type="hidden" name="formula">
<input type="hidden" name="nexturl" value="">
</form>
<body onLoad="GetStatus()">
<FORM name="frmStatus">
TESTGLOBAL called via Java GetStatus() Function
<INPUT TYPE="text" NAME="tvstatus">
</FORM>
</body>
</html>
=======================================================
My problems are in the GetStatus() function. Everytime I run the page the tvstatus text box returns 'undefined'. Have left some commented code in GetStatus to show how I've been trying to diagnose the problem but, not being a Java-ist, this has me stumped and I would be grateful for any advice on where I'm going wrong.
Am only using a text box at present until I can get the code to work then I'm looking to use a set of radio buttons to display and, if neccessary, modify the current state of IR controlled devices. Normally the on/off state will be managed programmaticallly within PH but I may need to set them manually in the event of devices getting out of sync. (Especially during developement of the front-end.)
Many thanks and happy new year to all.
Martyn
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 31 2004 at 11:24 | IP Logged
|
|
|
Martyn,
Im by no means a javascript expert but I don't think you can do what you want with javascript. It looks like you are trying to assign the output of the f_formula function within the GetStatus function and this wont work. The f_formula function does not return a value (at least not what you're expecting) and instead submits a form.
When the f_formula function is executed, it submits a request to the PH webserver. Basically you are requesting a new webpage from the server...http://phwebserver/ph-cgi/evalformula. This request can come in the form of an HTML POST or GET request (POST in this particular instance). You could also use a GET request and it would look something like: http://phwebserver/ph-cgi/evalformula?nexturl=&formula=ph_getglobal_n('TESTGLOBAL'). The PH webserver will take this request and in this instance will evaluate the formula. The result of the evaluation of the formula from the /ph-cgi/evalformula function is discarded. Depending upon the value in the "nexturl" parameter, the appropriate HTML will be passed back to the browser. In this case, you've redirected this returned HTML to another window called "blankframe" which keeps your main page from reloading.
Looking at your code, it appears that you want to serve a dynamic webpage showing the current status of a global variable. This would be perfect for PSP (PowerHome Server Pages). A PSP page is basically an HTML page (with an extension of .PSP) containing embedded PowerHome formulas. When this page is requested from the PH webserver, the embedded formulas are evaluated. After all of the formulas have been evaluated, the resulting HTML is passed back to the browser. So, to have a simple webpage that will show the current status of the TESTGLOBAL global variable everytime the page is refreshed, you could use the below PSP page:
<html>
<head>
<title>PSP Test</title>
</head>
<body>
TESTGLOBAL current status = <%ph_getglobal_s("TESTGLOBAL")%>
</body>
</html>
No javascript needed at all, however both PSP and javascript can be combined. So, PSP pages contain embedded PH formulas that are evaluated when the page is requested. After evaluation, the result is passed back to the browser. This result could contain javascript including the f_formula function so that new requests can be made. You may also want to check this recent post http://www.powerhomeautomation.com/forum/display_topic_threads.asp?ForumID=4&TopicID=391&PagePosition=1 for another example of PSP.
Hope this helps and let me know if you have any other questions.
Dave.
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: December 31 2004 at 12:18 | IP Logged
|
|
|
Dave
Tried the code supplied and it did what it said on the tin. Brilliant. Many thanks.
A little experimenting and I found that I could use
var sResponse = <%ph_getglobal_s("TESTGLOBAL")%>
as a direct replacement for my
var sResponse = f_formula('ph_getglobal_s(\'TESTGLOBAL\')');
I first tried on a PSP page and it worked perfectly but I lost the syntax colouring in Dreamweaver so, as an experiment, I pasted the line into my HTML page, (the one shown in my original post,) and it also seems to function as expected.
Once again, many thanks for a clear, consise, and prompt response to my query.
Regards
Martyn
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: December 31 2004 at 12:28 | IP Logged
|
|
|
Please disregard my last message about the function working on an HTML page. I was displaying the PSP page thinking it was the HTML. Oops.
Regards
Martyn
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: December 31 2004 at 13:30 | IP Logged
|
|
|
Just so that you can see what I was aiming for, I have added a couple of radio buttons both named grpTVStatus with the values 0 and 1.
I've updated the GetStatus function as follows:
function GetStatus()
{
var sResponse = <%ph_getglobal_n("TESTGLOBAL")%>
//This line added
document.frmStatus.grpTVStatus[sResponse].checked="true";
document.frmStatus.tvstatus.value = sResponse;
}
This now checks the correct radio button based on the value of sResponse 0 = Off, 1 = On.
It's now time to trim the fat out of the code and build a complete Status Page, (TV, DVD, VCR etc)
Couldn't have progressed this far without your help Dave.
Thanks
Martyn
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 31 2004 at 17:36 | IP Logged
|
|
|
Looking good Martyn. Glad to be of help.
Just want to add a few comments for others who may not be clear on PSP functionality
The PSP code is executed prior to the page being served. For example, the <%ph_getglobal_n("TESTGLOBAL")%> code is evaluated when the page is requested. The result of this function will then be passed back in the HTML. So what the browser will actually see is: var sResponse = 1. At this point, the browser will have no knowledge of what the PSP formula was because the browser will never see it (the browser has no idea what to do with PSP code anyway).
Just wanted to clear that up so that others would not look at your code and think that the ph_getglobal_n was actually being passed to the browser and being evaluated in Javascript.
Hope you get the pages working and would love to see the final result.
Let me know if I can be of further assistance.
Dave.
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: February 17 2005 at 13:57 | IP Logged
|
|
|
Dave
Have been trying for weeks to solve a problem regading the inline function <%ph_getglobal_n("TESTGLOBAL")%>.
It does exactly what I want when the PSP page is opened but during the normal course of operations the value of the "TESTGLOBAL" variable in PH is likely to change.
Is there any way to return the value of "TESTGLOBAL" without having to reload/refresh the webpage?
Many thanks
Martyn
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: February 17 2005 at 18:41 | IP Logged
|
|
|
I think the only way would be to use an iframe in the page and only refresh it.
Anyone with other ideas?
Tony
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: February 19 2005 at 04:20 | IP Logged
|
|
|
Thanks for the advice Tony. Will give it a try.
Martyn
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: February 19 2005 at 09:38 | IP Logged
|
|
|
Tony
E U R E K A !!! At last.
Many thanks for the idea.
Have set the page up with an iFrame which I can refresh without affecting the rest of the page. The source for the iFrame simply contains a javascript function to assign the PH variables to Flash variables. e.g.
parent.window.document.myFlash.setVariable("txtTest", <%ph_getglobal_s("TESTGLOBAL")%>);
To refresh the iFrame (named mHAPFunctions) I use:
window.frames["mHAPFunctions"].location.reload();
Just to make things a little more interesting I'm actually developing the interface using Flash so there's yet another layer of communication required. (PH -> web page -> flash) Not to worry though, I've already got that angle covered.
This project has been a real voyage of discovery for me as I've no experience of web page design or Flash so it's been, (and still is,) a really steep learning curve but it's made so much easier having the PH community to call on.
Thanks
Martyn
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 21 2005 at 14:53 | IP Logged
|
|
|
Martyn,
I would love to see your finished result when you've got it done. Sounds like it's really going to look cool with the flash.
Dave.
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: February 21 2005 at 15:50 | IP Logged
|
|
|
Will post a couple of screenshots as soon as I work out where my free webspace is with BTOpenworld.
Martyn
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: February 22 2005 at 02:45 | IP Logged
|
|
|
Here goes...
Have uploaded a couple of early screenshots of the interface.
my Home Automation Project (mHAP) early screenshots
The buttons top right on the Sat page are:
Orange: cycle through extra controls (numpad, favourites)
Green: Return to Home page
Red: Simulates Power button on Satellite remote control
The column of buttons on the right will be volume controls. Middle = mute, next one out = vol -/+ single step and the outer ones = vol -/+ large step. I've put them on the right because I'm hoping to use this interface from a 10" touch sensitive webpad/slate/tablet pc, and these buttons would be where you'd naturally hold the device.
Need to start adding symbols to other buttons
It's early days yet and things could still change but this is how they stand at present.
Martyn
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: February 22 2005 at 09:14 | IP Logged
|
|
|
Looking good, Martyn!
Tony
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 22 2005 at 17:28 | IP Logged
|
|
|
Definately looking nice!
Dave.
|
Back to Top |
|
|
MartynD Newbie
Joined: December 14 2004 Location: United Kingdom
Online Status: Offline Posts: 13
|
Posted: February 26 2005 at 16:02 | IP Logged
|
|
|
Dave/Tony
Very kind of you to say.
Thanks
Martyn
|
Back to Top |
|
|