Facility Control

 View Only
  • 1.  Listener "dot" indicator

    Posted 01-13-2020 13:59

    Hello, 

    I want to create indicator for my listener client. I want it to indicate also in case of server failure (disconnect that was initiated from server side). 

    So, i just created an test panel with 2 listener - 1 of them "server" listens to port 1223, and client server connects to port 1223 on localhost. So, basically, my idea was to assign to event.isConnectEvent() green color set to my indicator, and while event.isDisconnectEvent() assign red color. 

    I know there is  (listener.isStarted()) function, but i don't want to run it all the time, this is overkill i think.

    But, practically, my dot indicator starts to blink, i understand that event.isDisconnectEvent() happens all the time. 

    Any ideas, how to built it correct, and it should indicate disconnection from the server side too.

    Thanks!

    Here is this test panel:

     

    <abs contexttype="opengear" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" maxlength="0" name="led" oid="led" type="STRING" value="&lt;#ff0000&gt;" widget="dot"/>
    </params>
    </meta>
    <listener autostart="false" buttontype="toggle" connecthost="localhost" connectport="1223" delimiter="1" delimitertype="fixedlen" height="60" id="client" left="275" name="client listener on/off" style="t:style:navigationButton;f:style:navigationButton;" top="61" width="153">
    <task tasktype="ogscript">if (event.isConnectEvent())
    {

    params.setValue('led', 0, '&lt;#00ff00&gt;');// set led dot to green
    }


    else if (event.isMessageEvent())
    {
    //some work

    }

    else if (event.isDisconnectEvent()) {
    params.setValue('led', 0, '&lt;#ff0000&gt;'); //set led dot to red
    }</task>
    </listener>
    <listener autostart="false" buttontype="toggle" delimitertype="none" height="60" id="server" left="44" listenport="1223" name="server emulator on/off" style="t:style:navigationButton;f:style:navigationButton;" top="61" width="229"/>
    <param expand="true" height="33" left="455" oid="led" top="71" width="32"/>
    </abs>





  • 2.  RE: Listener "dot" indicator

    Posted 01-13-2020 19:23

    Hi Alex,

    Thanks for your query.

    Here is what I found for you.

    The DashBoard always depends on what's on the other side of the server.
    If its a flickering server then it will show as it is and Ideally any server should not do that way.

    But after playing with your panel, one of our developers helped to find a solution to your issue.

    We put a timer about 5 sec ,  check the status preventing LED blinking.

    1. If status is on , then LED will remain as green.
    2. If status is off and if it receives isconnect() command with in that time then LED will remain as Green
    3. else turn to Red.

    Here is updated task from your code.

    <task tasktype="ogscript">function connect()
    {
    params.setValue('led', 0, '&lt;#00ff00&gt;');// set led dot to green
    }

    function disconnect()
    {
    params.setValue('led', 0, '&lt;#ff0000&gt;'); //set led dot to red
    }

    if (event.isConnectEvent())
    {
    connect();
    //ogscript.debug("Connect, clear DC time.");
    ogscript.putObject("server.lastDCTime", 0);
    }


    else if (event.isMessageEvent())
    {
    //some work

    }

    else if (event.isDisconnectEvent()) {
    //disconnect();
    function runLater(resultStr)
    {
    var lastTime = ogscript.getObject("server.lastDCTime");
    var difference = new Date() - lastTime;
    //ogscript.debug("It's been " + difference + " since DC. Last time was " + lastTime);
    if (lastTime != 0 &amp;&amp; difference &gt; 5000)
    {
    ogscript.debug("Disconnecting.");
    disconnect();
    }
    }

    var t = ogscript.asyncExec(runLater, 5100);
    var time = new Date();
    //ogscript.debug("DC, set DC time to " + time);
    ogscript.putObject("server.lastDCTime", time);

    }</task>

     


    There is still problem with this solution as its not a real time solution with non-ideal server.

    For the first time you open the panel Or when you reload (F5) , it will loads to state which you saved last time.

     

    Let me know if you require any further information on this.

     

    Regards,
    Anand


    #DashBoard


  • 3.  RE: Listener "dot" indicator

    Posted 01-16-2020 09:43

    Hello Anand

    Thank you for that answer, I found it too complicated and overkill to run thousands of async.exec's every second. Here is an example for more elegant solution for that kind of connection - i just restart the timer every time that is event.isConnectEvent() happens. In timer task, if the timer is running - then dot=green, else = dot = red. This is not ideal too, but this is only 1 sec delay (it could be even less if you decrease timer value - i just don't want to rus tasks too frequently).

    For the first time you open the panel Or when you reload (F5) , it will loads to state which you saved last time.

    There is a way to solve that. You can create <API> task and check "Execute immediately" - so, that means the task will run only on startup - in this task you can reset the dot color to red. 

    Here is the example panel :

    <?xml version="1.0" encoding="UTF-8"?><abs contexttype="opengear" id="_top" keepalive="false">
    <timer autostart="false" id="timer" pattern="HH:mm:ss" rate="500" start="00:00:01" stop="00:00:00">
    <timertask tasktype="ogscript">var timer = ogscript.getTimerManager().getTimer('timer');
    if (!ogscript.getListenerById('client').isStarted() ){
    params.setValue('led', 0, '&lt;#ff0000&gt;'); //if listener is off,set led dot to red
    }


    if(timer.isRunning()){
    params.setValue('led', 0, '&lt;#00ff00&gt;');// set led dot to green
    } else {
    params.setValue('led', 0, '&lt;#ff0000&gt;'); //set led dot to red
    }</timertask>
    </timer>
    <meta>
    <params>
    <param access="1" maxlength="0" name="led" oid="led" type="STRING" value="&lt;#ff0000&gt;" widget="dot"/>
    </params>
    </meta>
    <listener autostart="false" buttontype="toggle" connecthost="localhost" connectport="1223" delimiter="1" delimitertype="fixedlen" height="60" id="client" left="275" name="client listener on/off" style="t:style:navigationButton;f:style:navigationButton;" top="61" width="153">
    <task tasktype="ogscript">if (event.isConnectEvent())
    {

    ogscript.getTimerManager().getTimer('timer').startTimer(true); //restart timer each message

    }


    else if (event.isMessageEvent())
    {
    //some work

    }

    else if (event.isDisconnectEvent()) {

    }</task>
    </listener>
    <listener autostart="false" buttontype="toggle" delimitertype="none" height="60" id="server" left="44" listenport="1223" name="server emulator on/off" style="t:style:navigationButton;f:style:navigationButton;" top="61" width="229"/>
    <param expand="true" height="33" left="455" oid="led" top="71" width="32"/>
    </abs>

     


    #DashBoard


  • 4.  RE: Listener "dot" indicator

    Posted 01-16-2020 13:19

    Hi Alex,

    That's wonderful!

    I guess you have got all working now.

    Please feel free to post here for any issues you come across.

     

    Thanks,

    Anand


    #DashBoard