Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Location
    Orange County, NY
    Posts
    936

    iLon JavaScript function()

    Hello Gentlemen.

    I’m still learning my way around the LonWorks platform and I have a question about displaying NVE’s or any other data point in multiple web pages.

    Lets assume we have a node that measures outside air, we will say it’s a NVO_Analog_out / SNVT_Lev_Percent. We have 10 rooftop units and 10 separate web pages, one per rooftop, that displays system data including the outside air temp.

    Clearly a “Show Value” layer can be used on each page to display our NVE_Anolog_sensor.

    Would it be better to create a JavaScript “function ()” like so:

    function OAtemp()
    {
    var adjTemp=Math.round(AirTemp*100)/100;
    return adjTemp;
    }
    var aTemp=<iLonWeb FUNC=ShowValue
    SYMBOL=NVE_RIBAIRm_Sensor></iLonWeb>;
    var AirTemp=(aTemp/100)*163.835;
    OAtemp();
    var OA=OAtemp();
    document.write(OA);

    This script would be saved in the “forms” directory of the iLon.

    Then any time I wanted to display this Point I would just call the Script in the code.

    Example:

    <script language="JavaScript" src="/forms/test.js"></script>

    The “test.js” is the above JavaScript code.
    Is this a practical way?

    Respectfully,

  2. #2
    Join Date
    Mar 2003
    Location
    NY
    Posts
    2,144
    I guess my first question would be, why are you using web tags instead of using iLON Vision? In Vision you can create one page and 'substitute' values for all ten rooftops. Web tags offer some advantages but Echelon is no longer supporting them as of the e4. I'm of the opinion that it is a little late to learn web tags at this point, although I just recently fooled with them to create a page that I could open in a Blackberry.

    With that said, what you are asking makes sense. In fact you can create a .js file with many functions that can be called in you web pages. I do something similar with JavaScript functions to be used with Vision pages.

  3. #3
    Join Date
    Sep 2002
    Location
    Hampton Roads, Virginia
    Posts
    1,600
    First of all, if you have ten RTU's that are basically the same, you should/can use one page to display them all, it took me a while but understanding the substitution ability will save you a huge amount of work.
    Secondly <iLONWeb> tags are history, yes they will still work with the e3 but after that probably not. Create Text fields for our data points in contribute (make sure you have them all before proceeding), then use Javascript to display them in the format you want, see me code below.
    Thirdly, Javascript files go in the scripts folder, you can create folders in there, just link to them like in my sample code.

    Web page code
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script type="text/javascript" src="/scripts/cii/krogers.js"></script>

    <!-- ECHELON-OBJECT 3.0 script BEGIN. DO NOT EDIT OR DELETE -->
    <script type="text/javascript" src="/scripts/echelon/STDAppControlObject.js"></script>
    <script type="text/javascript"><!--
    function echelonInit() {
    if(window != top && this.ControlObject) {
    ControlObject.getInstance().pageLoaded = true;
    ControlObject.getInstance().init();
    }
    else {
    ControlList.initStatic();
    }
    setTimeout("showval()",6000);
    }
    // -->
    </script>
    <!-- ECHELON-OBJECT 3.0 script END -->
    <script type="text/javascript"><!--
    function showval(){
    document.getElementById('OAT').innerHTML = round1(document.getElementById('ILO-14-TXF').value) + "&#186;F"
    document.getElementById('AvgTemp').innerHTML = round1(document.getElementById('ILO-10-TXF').value) + "&#186;F"
    document.getElementById('AvgLoad').innerHTML = round0(document.getElementById('ILO-11-TXF').value) + "&#37;"
    document.getElementById('LoadType').innerHTML = document.getElementById('ILO-12-TXF').value
    document.getElementById('Tim').innerHTML = time12hour(document.getElementById('ILO-13-TXF').value)
    timerID = setTimeout("showval()",2000);
    }
    //-->
    </script>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Main</title>
    <style type="text/css">
    <!--
    .style3 {
    font-family: Arial, Helvetica, sans-serif;
    color: #0000FF;
    }
    -->
    </style></head>
    <body onLoad="echelonInit();">



    <div style="left: 144px; top: 294px; width: 312px; height: 70px; z-index: 1; position: absolute; " >

    <!-- ECHELON-OBJECT 3.0 showvalue BEGIN. DO NOT EDIT OR DELETE -->
    <div id="ILO-9-SHV">ON/OFF</div>
    <script type='text/javascript'><!--
    try{
    ControlList.addItem("showvalue", "ILO-9-SHV", "NVL_message", { "showValueDef": false,"showUnit": false}, { "hideDPName": false});
    } catch(e) { ; }
    // -->
    </script>
    <!-- ECHELON-OBJECT 3.0 showvalue END -->
    </div>

    <div style="left: -317px; top: 238px; width: 312px; height: 70px; z-index: 1; position: absolute; " >
    <!-- ECHELON-OBJECT 3.0 textfield BEGIN. DO NOT EDIT OR DELETE -->
    <input type="text" id="ILO-10-TXF" style="text-align: left" >
    <script type='text/javascript'><!--
    try{
    ControlList.addItem("textfield", "ILO-10-TXF", "NVL_AvgTemp", { "showValueDef": false,"showUnit": true}, { "hideDPName": false});
    } catch(e) { ; }
    // -->
    </script>
    <!-- ECHELON-OBJECT 3.0 textfield END -->

    <div style="left: -32px; top: -426px; width: 100px; height: 50px; z-index: 1; position: absolute; " >

    <!-- ECHELON-OBJECT 3.0 textfield BEGIN. DO NOT EDIT OR DELETE -->
    <input type="text" id="ILO-11-TXF" style="text-align: left" >
    <script type='text/javascript'><!--
    try{
    ControlList.addItem("textfield", "ILO-11-TXF", "NVL_AvgLoad2", { "showValueDef": false,"showUnit": true}, { "hideDPName": false});
    } catch(e) { ; }
    // -->
    </script>
    <!-- ECHELON-OBJECT 3.0 textfield END -->
    </div>
    </div>
    <div style="left: 643px; top: 163px; width: 150px; height: 50px; zIndex: 1; position: absolute; z-index: 1">Average RoomTemp.:</div>
    <div style="left: 642px; top: 194px; width: 152px; height: 50px; zIndex: 1; position: absolute; z-index: 1">Average Demand :</div>
    <div style="left: -1254px; top: 108px; width: 100px; height: 50px; z-index: 1; position: absolute; " >

    <!-- ECHELON-OBJECT 3.0 textfield BEGIN. DO NOT EDIT OR DELETE -->
    <input type="text" id="ILO-12-TXF" style="text-align: left" >
    <script type='text/javascript'><!--
    try{
    ControlList.addItem("textfield", "ILO-12-TXF", "NVL_LoadType", { "showValueDef": true,"showUnit": false}, { "hideDPName": false});
    } catch(e) { ; }
    // -->
    </script>
    <!-- ECHELON-OBJECT 3.0 textfield END -->
    </div>
    </div>
    <div style="left: -200px; top: -20px; width: 100px; height: 50px; z-index: 1; position: absolute; " >

    <!-- ECHELON-OBJECT 3.0 textfield BEGIN. DO NOT EDIT OR DELETE -->
    <input type="text" id="ILO-13-TXF" style="text-align: left" >
    <script type='text/javascript'><!--
    try{
    ControlList.addItem("textfield", "ILO-13-TXF", "NVL_nvoRtTimeDate", { "showValueDef": false,"showUnit": false}, { "hideDPName": false});
    } catch(e) { ; }
    // -->
    </script>
    <!-- ECHELON-OBJECT 3.0 textfield END -->
    </div>
    <div style="left: -200px; top: 20px; width: 100px; height: 50px; z-index: 1; position: absolute; " >

    <!-- ECHELON-OBJECT 3.0 textfield BEGIN. DO NOT EDIT OR DELETE -->
    <input type="text" id="ILO-14-TXF" style="text-align: left" >
    <script type='text/javascript'><!--
    try{
    ControlList.addItem("textfield", "ILO-14-TXF", "NVE_320nvoValueUI_00", { "showValueDef": false,"showUnit": false}, { "hideDPName": false});
    } catch(e) { ; }
    // -->
    </script>
    <!-- ECHELON-OBJECT 3.0 textfield END -->
    </div>
    <div style="left: 3px; top: 289px; width: 309px; height: 40px; zIndex: 1; position: absolute; z-index: 1">System Messages: </div>
    <div id="OAT" style="left:816px; top:134px; position:absolute; font-size:14px; width: 64px;">Temp</div>
    <div id="Tim" style="left:817px; top:97px; position:absolute; font-size:14px; width: 72px;" onMouseOver="return escape('Time read from ilon100, this is updated from a timeserver. All other controllers on this system are synchronized to the ilon100')" >Time</div>
    <div id="AvgTemp" style="left:816px; top:163px; position:absolute; font-size:14px; width: 64px;">Temp</div>
    <div id="AvgLoad" style="left:837px; top:194px; position:absolute; font-size:14px; width: 64px;">Temp</div>
    <div id="LoadType" style="left:766px; top:195px; position:absolute; font-size:14px; width: 81px;"></div>
    <p align="left">&nbsp;</p>
    <p>
    <script type="text/javascript" src="/scripts/cii/wz_tooltip.js"></script>
    </p>
    <div style="left:10px; width:570px; top:120px; position:absolute" id="text">

    </div>
    <div style="left:10px; top:550px; width:20px; position:absolute;">
    </div>


    </body>
    </html>



    Script file code




    function round1(rtotal) { // Round to one decimal place
    rtotal = Math.round(rtotal*10)/10;
    return (rtotal.toFixed(1));
    }



    function round0(rtotal) { // Round to zero decimal place
    rtotal = Math.round(rtotal);
    return (rtotal);
    }

    function round2(rtotal) { //Round to 2 decimal place
    rtotal = Math.round(rtotal*100)/100;
    return (rtotal.toFixed(2));
    }


    // Copyright 2006 Bontrager Connection, LLC
    function WriteContentIntoID(id,content) {
    if(document.getElementById) {
    var idvar = document.getElementById(id);
    idvar.innerHTML = '';
    idvar.innerHTML = content;
    }
    else if(document.all) {
    var idvar = document.all[id];
    idvar.innerHTML = content;
    }
    else if(document.layers) {
    var idvar = document.layers[id];
    idvar.document.open();
    idvar.document.write(content);
    idvar.document.close();
    }
    }





    function timeonly(Tim) { // Extract time in 24 hour format from LON date/time string
    var mit = 0
    mit = (Tim.split(" "));
    return mit[1]
    }

    function time12hour(Tim) { // Input LONdate/time string return time only in AM/PM format
    var mit = 12
    var gs = 12
    gs[0]= 12 // to stop undefined messages on startup
    gs[1]= 59
    gs[2]= "AM"

    mit = timeonly(Tim);
    gs = (mit.split(":"))

    if(gs[0] < 12){
    gs[2] = "AM"
    }
    if(gs[0] > 12){
    gs[0] = (gs[0] - 12);
    gs[2] = "PM"
    }
    if(gs[0] == 12){
    gs[2] = "PM"
    }
    if (gs[0] < 1){
    gs[0] = 12 ;
    gs[2] = "AM"
    }


    return (gs[0] + ":" + gs[1] +" " + gs[2])

    }


    function dateonly(Tim) {
    var mit = 12
    var dat = 12
    mit = (Tim.split(" "));
    dat = (mit[0].split("-"));
    return (dat[1] + "-" + dat[2] + "-" + dat[0]);
    }


    function fontcol(low,valu,high) { // Color font based on value

    var range = 2
    range = (high - low)
    var scale = 2
    scale = (range/5)
    if(valu <=low) { return valu.fontcolor("blue")
    }

    else if(valu <= (low + scale)) {return valu.fontcolor("navy")
    }
    else if(valu >= high) {return valu.fontcolor("red")
    }
    else if(valu >= (high - scale)) {return valu.fontcolor("maroon")
    }

    else {return valu.fontcolor("black")
    }
    }

    Any question please feel free to ask, I or other will help as much as possible

    Kevin
    Last edited by klrogers; 02-18-2008 at 07:37 PM.
    "Profit is not the legitimate purpose of business. The legitimate purpose of business is to provide a product or service that people need and do it so well that it's profitable."

    James Rouse

  4. #4
    Join Date
    Sep 2002
    Location
    Hampton Roads, Virginia
    Posts
    1,600
    Had to cut some code out to allow it to fit in 1 post so cut/pasting may not work. But hope you can get the idea.

    Kevin
    "Profit is not the legitimate purpose of business. The legitimate purpose of business is to provide a product or service that people need and do it so well that it's profitable."

    James Rouse

  5. #5
    What am I missing? I tried this, but now I have the original text field, as well as the new rounded variable on the web page. Having to create another variable is acceptable, but I was hoping to be able to directly round the value in the text field. I sure don't need both on the page though.

    Any help would be greatly appreciated!
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comfortech Show Promo Image

Related Forums

Plumbing Talks | Contractor Magazine
Forums | Electrical Construction & Maintenance (EC&M) Magazine
Comfortech365 Virtual Event