Topic: Having trouble with GETPARAM

Can't seem to read the parameters in javascript.  If I enter the commands via URL i get back the correct quasi XML.

Here is what I'm doing

        xmlhttpa=new XMLHttpRequest();
    xmlhttpa.open("GET","http://localhost/bridge?cmd=getparam&value=boxid",false);
    xmlhttpa.send();
    xmlDoc=xmlhttpa.responseText;
   
xmldoc seems to be null.

Re: Having trouble with GETPARAM

How did you set your 'boxid' variable? Did you manually put it in /psp/parameters.ini?
This won't work for your current firmware because /psp/parameters.ini is loaded into memory only once everytime the browser starts.
If you have use SetParam & then GetParam immediately after that, it will work.

I'm going to reload /psp/parameters.ini every time GetParam or SetParam is called in firmware 22.
There is also a new command GetParams for your convenience.

You can safely substitute your /usr/bin/NeTVServer with the latest binary here http://files.chumby.com/torin/NeTV/NeTVServer
It shouldn't break any of your existing code. Remember to chmod +x

Btw, I don't know what your 'boxid' is, but there is a unique GUID for each device in 'hello' command. Just a suggestion.

Re: Having trouble with GETPARAM

Here is what we are trying to do -

We need to uniquely identify each box with an ID into a database.  We have switched to the GUID funtion and that works.  We've built a script that generates it and we pipe that result into a txt.

We can't seem to find a way to read that value into JS.  It becomes an argument to our server. (right now hard coded at 1).  We even tried to create a guid.js file that would return the value, but could not get the web page to read that in as script source.

We're a little stuck at the moment trying to solve this.  I need a little JS snippet that will return a string that is the GUID that I can tack on as a parameter to a server call using XMLhttpRequest call.  We have server that can take the argument on the passed url and return XML.  We are happily parsing that XML and all is grand.  Just can't get the darned GUID to move through.

Below is the the function -  You will notice the boxid=1.  That's what we want to make unique to each box.


function poll()
{
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("GET","schedule.php?boxid=1",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;
   
    if (xmlDoc.getElementsByTagName("action")[0].childNodes[0].nodeValue == "goto") {
        window.location=xmlDoc.getElementsByTagName("url")[0].childNodes[0].nodeValue;
    }
   
    if (xmlDoc.getElementsByTagName("action")[0].childNodes[0].nodeValue == "download") {
        var fname=xmlDoc.getElementsByTagName("fname")[0].childNodes[0].nodeValue;
       
        xmlhttpdl=new XMLHttpRequest();
        xmlhttpdl.open("GET","http://localhost/scripts/download.sh?file="+fname,false);
        xmlhttpdl.send();

    }


}

Re: Having trouble with GETPARAM

You can take a look at the recommended way to issue a Hello command & assign a callback to catch the result in
/usr/share/netvserver/docroot/widgets/helloworld_0.1/script.js

You can call your poll() function in helloCallback. helloData['guid'] is what you want.

The way that you are doing it here seems frisky to me, especially when your server is a real online server, not localhost.
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
It is better to do this asynchronously & not freeze the UI.

Re: Having trouble with GETPARAM

even tried the following -
    <script type="text/javascript" src="http://localhost/scripts/guid.js"></script>

where guid.js is a file we built on the fly to return the guid as a function call.

function getguid() {return ("169C9111-D428-6B2E-9D72-5530FFCE8B27");}

no go.  don't think script include works.  We noticed that when the url is called it does something different than most webservers.  normally you just get the text of the JS files.  with netv it tries to down load the file and fails.

6 (edited by torinnguyen 2011-11-02 07:58:56)

Re: Having trouble with GETPARAM

Wow! This is unexpected.
I thought you were asking for CGI-BIN like stuff, so I assumed you were asking for perl or shell scripts.
The script support feature is never meant for JavaScript.

Here's what you need to do:
1) create guid.sh in /usr/share/netvserver/docroot/scripts
The content is just 2 lines:
#!/bin/sh
guidgen.sh

2) make sure it is executable
chmod +x /usr/share/netvserver/docroot/scripts/guid.sh

3) execute it (not include it) as http://10.0.88.1/scripts/guid.sh

If it gives you blank value, check step (2)


To explain why your simple include failed.
http://localhost/scripts is specially handled by NeTVServer to execute shell scripts, it will not work if you host JavaScript files in there.

Re: Having trouble with GETPARAM

We reached a similar conclusion.  We decided to pull all the polling and scheduling stuff out of JS and move it into shell scripts. 

We were jumping through to many hoops and were running into reliability issues.

So, when JS needs to poll (and we will move this to cron later). it calls a shell script.  that script has all the info it needs (guid etc.)

works great and is much more reliable.

thanks as always for your help.

dan