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.
- If status is on , then LED will remain as green.
- If status is off and if it receives isconnect() command with in that time then LED will remain as Green
- else turn to Red.
Here is updated task from your code.
<task tasktype="ogscript">function connect()
{
params.setValue('led', 0, '<#00ff00>');// set led dot to green
}
function disconnect()
{
params.setValue('led', 0, '<#ff0000>'); //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 && difference > 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