Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: How to pass parameters from a psp page? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 08 2006 at 15:22 | IP Logged Quote onhiatus

So I thought I knew how to do this, but I am suddenly stumped.

It's easy enough to have a psp page run macros, but this happens when the page is being rendered. Now I'm trying to pass a macro a parameter based on a selection on a web page - and I can't figure out how to do it!

I've got a select box that has about a thousand music artist and I'm trying to have powerhome play all the music by the selected artist when a button is pressed.

I've written a macro that takes the artist name in Local1 and plays everything - this works great. So to call it through a psp page I'd use:
     <% ph_macroparm("PLAY ARTIST", "Pete Townshend", 0, 0, 0, 0) %>
To play everything in my collection by Pete Townshend.

The problem is this plays on load - I want the string to come from a select box when the button is pressed.

In the page I'm trying to write a function that takes the artist's name and somehow launches the above macroparam call.

I'm trying to write a function that is called from this html in the php page:
     <button onclick="playArtist(asearch.artistList.options[asearch.artistList.selectedIndex].text);" name="playAll" style="width: 140; height: 60">
     <font size="3">Play All</font></button>

The function would somehow trigger the above macro call. So far it looks like this:
     function playArtist(artist)
     {
     }
Obviously it needs some work!

Any suggestions for what goes in side the function?

I'm pretty certain I'm missing something very basic here, but the only solution I've been able to come up with involves writting a psp page for each artist!

Help! Thanks, Tony
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 08 2006 at 17:29 | IP Logged Quote TonyNo

What you need to use is the ph_getwebparm function.

Look at this thread.

Another example is my macro listing PSP page thread.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 08 2006 at 23:00 | IP Logged Quote onhiatus

Yep, that it. Thanks!

Here's a helpful hint for people doing this kind for thing where you don't want to change pages. Dave's example (see link above) used a redirect to return to the macro page. Kind of ugly as you loose your state and the screen refreshes. I avoid this by setting a target in the form. Then in the psp page I have an iframe which has style="display: none;". Now when I click the submit button the action psp page gets loaded into the iframe (executing the macro in the process) but you can't see it - to the user you are still on the same page and can do something else.

Hope that made sense

-Tony OnHiatus
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: October 09 2006 at 14:20 | IP Logged Quote dhoward

Tony,

This is the technique that is used on the Web based Control Center except that the target frame has a height of 0. Using the style="display:none", do you know if this is universal across browsers including Pocket IE? Might be a change that I want to implement for the Web CC?

Thanks,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 09 2006 at 17:49 | IP Logged Quote onhiatus

I'm not sure. I'm going to guess it won't work for pocket IE (it's been a while but I actually worked on version 1.0...)

I'll check firefox and pocket ie tonight and let you know.
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 09 2006 at 19:11 | IP Logged Quote TonyNo

Mix this in with some AJAX-type coding and I'm all over it! No refresh is great, but things still need to be updated.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 09 2006 at 23:12 | IP Logged Quote onhiatus

First - Dave - yes the display:none style seems to be honored by both Firefox and pocket IE (Windows Mobile 2003)

2nd Tony - The way I handle this is that I have a data iframe that is invisible that just reloads every five seconds. Then I have some java script that polls the Iframe every 1 second. The data is time stamped, so as long as nothing has changed the js does nothing, but when there is a change the data is parsed and my screen updates - no flicker! It actually all works very well - worst case is about a 10 second delay on the current song updating.

Besides current playing music, I also display my schedule (from Outlook) - immediate and a perpetual calendar (all read only), weather predictions (scraped from weather.com), live temperature settings from around my hose, and local traffic. Control wise right now is pretty minimal. I can Pause / Play / Next / Last the music, and play music by artist. Lights, fan, etc will be easy - there's been no hurry since my touch screen is located next to a smarthome switch that controls all of the above...

Another couple tricks I'm using:

1 - I use a super simple hta app to host an iframe - so I end up with no browser controls, no system controls - the entire screen is mine and it does not look like a web page.

2- I use a couple of semi transparent divs for "dialog boxes" - the result is that I can pop up details, disable the controls underneath ("modal") but still see what's going on in the background. Pretty much everything can be expanded for more detail.

3 - I sort the music list using a regular expression (sort of like A9 on a cell phone), so hitting the button [abc] and then [def] will match Ad*, Ae*, Da*... (rex: [abc][def]) makes sorting the artists very easy

A few screen shots:


Home page as of right now: (similar to previous post)


With Wednesday's details popped up:


The music collection with rex filtering:


The montly view of the calendar:



Can you tell the wife is out of town again?

Comments / suggestions always apreciated, Tony
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 10 2006 at 07:05 | IP Logged Quote TonyNo

Can you post details on your code (what's in the iframe and such)?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 10 2006 at 13:05 | IP Logged Quote onhiatus

Which iframe? The data iframe?

Currently the data.psp page delivers an html page with a ton of named spans. The first span is named "version", the others are then "data1", "data2", etc. Each updatable area (also spans) on the home page matches one of the data spans with something like "field1", "field2", etc. I then have a timed function (every 1 second) in the client java script that tries to parse the data iframe - if it throws an exception it tries again (5 times), then every 20 seconds until it goes through - in case the server goes down. The parsing loop looks at the version - when it changes it just looks for dataX and copies the contained html to fieldX - where X starts as 1 and is incremented until it fails. When it fails it's done. I currently have 60-something fields. The advantage is when I add some new data I don't have to change the code. The disadvantage is I have to keep the data.psp list synched with the html page.

I'm going to rewrite stuff soon - currently data.psp delivers ALLthe data everytime. It only gets parsed when there is a change, but changes occure every few minutes... I'm going to change it so that there are a bunch of data pages. The data.psp page will deliver a list of timestamps for each kind of data. When the main page sees a change it will cause that specific data frame to refresh (I imagine I'll leave the now playing data in the version list as I want it to react as quick as possible). I'll break out the calendar data as it only changes once per day (or on demand), the weather data (only changes every three hours), and the temperature data (changes fairly often). The musician's list is currently only updated on demand.

Another possibility would be to name the data fields and the display fields the same and have the client send the lastupdate time (version) with the data request. Then the data psp page would only return the things that had changed. Parsing would then just look at all spans and use the data span name to find the display field. Disadvantage is that generating the data file would be a lot more intensive and I would have to maintain a time stamp for every piece of data in powerhome.

Also note that some of the processing is done on the client page (day names, the calendars, how many days can be displayed without forcing scrolling).

The day lists / weather icons are calculated so that one to seven days might be displayed with schedules and three to five more days show the weather as icons - if you look at the first screen above, there are actually seven day lists, and nine weather icons. Since the first five days fit on the display area, the first five weather icons are hidden. If the first day "Today" had many appointments it might be the only one that was listed out - in that case the next five days would be displayed as icons (Tu, We, Th, Fr, Sa) and then last 4 icons would be hidden (Su, Mo, Tu, We)

When I get things a little farther along I'll try to set it up so visitors can see it - I've looked at your page before.

Let me know if you need it and I can share the actual specific jave script code for parsing when I get home.

-Tony

Edited by onhiatus - October 10 2006 at 14:01
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 10 2006 at 23:26 | IP Logged Quote TonyNo

I was hoping to see your client javascript and the data iframe (updating spans is something I do now, but only the time continuously and some SVG elements on loading).

Edited by TonyNo - October 10 2006 at 23:37
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 15 2006 at 16:24 | IP Logged Quote onhiatus

Sorry for the delay - I got distracted.

Here's what the data file looks like (data.psp) - I've shortened it as it's just processed in a loop:
Data.psp wrote:
<HTML>
<HEAD>
<meta HTTP-EQUIV="Refresh" CONTENT="5;http://livingroom/data.psp">
0
</HEAD>
<BODY>
<span name="TimeStamp">19:59:47</span>
<span name="1-Livingroom">70.9</span>
<span name="2-Outside">55.6</span>
<span name="3-Water">62.8</span>
<span name="4-Artist">Darden Smith: On The Mountain</span>
<span name="5-Song">Little Victories</span>
</BODY>
</HTML>


The java script that parses this:
Home.html wrote:
function updateFields() {
     var sd = window.frames[2];

     // Check to see if data has changed
     if(sd.document.body.all[0].innerHTML == dataLast) return;
     else dataLast = sd.document.body.all[0].innerHTML

     // Clear log
     log.innerHTML="";
     
     for (var j = 1; j < sd.document.all.length; j++) {
               var dataId = "data" + j;
                   var dataSrc = sd.document.body.all[ j ];
                   var dataDest = document.all(dataId);
                   if (dataSrc==null) {log.innerHTML+="<br>Err Src " + j; break; }
                   if (dataDest==null) {log.innerHTML+="<br>Err Dest " + dataId; break; }
                   dataDest.inn erHTML = dataSrc.innerText;
         }
    hideDays();
    changeIcons();
    return;
}


Finally, the data frame looks like this

Home.html wrote:
<iframe id="dataFrame" name="dataFrame" src="data.psp" style="display:none"> </iframe>

I actually have this frame displayed on the control tab for debug purposes - but the above is how it was originally used.

Hope this makes enough sense, let me know if you want to see more of it.

Good luck, Tony (OnHiatus)

Edited by onhiatus - October 15 2006 at 22:20
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 15 2006 at 21:09 | IP Logged Quote TonyNo

So, does this update matching spans?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 15 2006 at 22:19 | IP Logged Quote onhiatus

Yes. The lines inside the loop do this (note I changed the loop index to "j" because bracket i bracket was being interpreted as italic):
home.html wrote:
var dataId = "data" + j;
var dataSrc = sd.document.body.all [ j ];
var dataDest = document.all(dataId);
...
dataDest.innerHTML = dataSrc.innerText;


The first line names the span that it will be copying into (e.g. "dataX"), the second line looks for the Xth element in the data frame, the third line looks up the span names in the first line (dataX)

The data fields are just spans, for example:
home.html wrote:
<span id="data1">Livingroom temp will go here</span>

Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 16 2006 at 07:23 | IP Logged Quote TonyNo

Thanks! I'll see what I can do with this.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 16 2006 at 18:19 | IP Logged Quote onhiatus

Note that you'll want to add some error handling - I use a try loop around the timer function that calls updateFields(). Since the loading and parsing of data.psp (in my example) are asynchronous you will occasionally have collisions.

My data.psp refreshes itself every five seconds. The above issue could be minimized if the javascript did the refreshing instead - plus could possible get a higher frequency resulting in less latency.
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 16 2006 at 20:37 | IP Logged Quote TonyNo

Do you use IE or Firefox? I can see the tab flashing in FF when the invisible iframe refreshes.

I also ran into an issue with...

Code:
if (sd.document.body.all[0].innerHTML == dataLast)


Which was...

Quote:
Error: sd.document.body.all has no properties
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 17 2006 at 01:33 | IP Logged Quote onhiatus

I predominantly use IE (actually an IE instance incapsulated in an hta app. I have tested on Firefox, and lots of my page does not display correctly, but the background update definitely works without causing the screen to flash!

If you really think it's the hidden iframe, then follow daves suggestion and use an iframe with a height of 0, or an absolute position that is off the screen.

Now the js update does not work when I run under firefox, so you'll have to work on how to access the data frame. But it really shouldn't be to big of a problem...
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 17 2006 at 07:42 | IP Logged Quote TonyNo

I forgot to mention that it also does not update in IE.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 18 2006 at 16:58 | IP Logged Quote onhiatus

Hmm, what do you mean it does not update in ie.

The data frame doesn't update, or the code doesn't update the visible spans from the data frame?

Also, I reread your message two ago and you said "I can see the tab flashing in FF when the invisible iframe refreshes". Does that mean the screen does not flash - just the tab at the top of the screen? If so do you show this tab from your touch screen? Isn't there someway to display full screen with no controls to maximize your screen realestate, and improve asthetics?

Let me know what the problem is, and I'll try to debug.
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: October 18 2006 at 19:15 | IP Logged Quote TonyNo

The code doesn't update the visible spans.

Yeah, the tab flashing is not a big deal when in kiosk mode. No worries!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 

Page of 2 Next >>
  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum