Logic Machine Forum
Force reload? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Force reload? (/showthread.php?tid=596)



Force reload? - Thomas - 06.02.2017

Hi
Is it possible somehow to force a client to reload the visualisation page(s) after I make a change?

Thank you


RE: Force reload? - Erwin van der Zwart - 06.02.2017

Hi,

Yes that is possible by custom javascript.

You need a event listener on a KNX object and a function to reload the client ( location.reload(); )

There is just 1 but... The client has to load the custom javascript first, so you have to reload them once after adding this, from then you can always force a client reload with your KNX object.

Can you do this or do i need to create a sample? (done this already on project so i must have it already somewhere)

BR,

Erwin


RE: Force reload? - Thomas - 06.02.2017

May you please provide me a sample?

Thank you


RE: Force reload? - Erwin van der Zwart - 06.02.2017

Hi Thomas,

Try this as custom JavaScript:

Code:
$(function(){
 if (typeof grp != 'undefined') {
   grp.listen('1/1/1', function(object, state) {
     var value = object.value;
     if (state == 'value') {
       if (value == 1) {
         location.reload();
         grp.update('1/1/1', false);
       }
     }
   }, true);
 }
});

When writing value true to '1/1/1' (bit object) the client will reply with value false to confirm that the location.reload()  has been triggered.

BR,

Erwin


RE: Force reload? - Thomas - 07.02.2017

Perfect. It works like a charm on both visualisations.
Thank you


RE: Force reload? - Thomas - 08.05.2018

Hi
I've found a problem. This script crashes LM. In my case everytime. I don't know if it depends on number of clients or size of the visu. Would it be possible to add some random delay for better load balancing?
Thank you


RE: Force reload? - Erwin van der Zwart - 08.05.2018

Hi,

This function runs client side and does nothing special other then refreshing the browser, same as pressing F5. When you press F5 on the client, do you see same issue? Are there errors in the browser console?

BR,

Erwin


RE: Force reload? - admin - 08.05.2018

How many active clients do you have?


RE: Force reload? - Erwin van der Zwart - 08.05.2018

Hi,

If you have a lot of clients you could add a random delay to divide all request to the controller at once by using this:

Code:
$(function(){
if (typeof grp != 'undefined') {
  grp.listen('1/1/1', function(object, state) {
    var value = object.value;
    if (state == 'value') {
      if (value == 1) {
        var x = Math.floor((Math.random() * 10000) + 1);
        setTimeout(function(){
           location.reload();
        }, x);
        grp.update('1/1/1', false);
      }
    }
  }, true);
}
});
BR,

Erwin