Logic Machine Forum
Problems with javascript write to bus - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Problems with javascript write to bus (/showthread.php?tid=3338)



Problems with javascript write to bus - Alexander - 03.05.2021

Hi,

I am trying again. Hope somebody can help me Smile
Code:
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script src="http://192.168.10.111/apps/js/jquery.js.gz"></script>
  <script src="http://192.168.10.111/apps/js/localbus.js.gz"></script>
  <script src="http://192.168.10.111/scada/vis/busdecode.js.gz"></script>
</head>
<body>
<script>

$(function() {
  // listen to all groupwrite telegrams
  localbus.listen('groupwrite', function(event) {
    console.log(event);

  });

  localbus.init('http://192.168.10.111, admin:admin');

 

});
</script>
</body>
</html>
I found this code from another post her in the forum, but I need some help to get it right.
I am trying to write a value from my browser to LM, I have tried different codes but I think there is no connection between the javascript and LM.
And when I check the console in my browser no errors are there, but no log info from the bus either.

What am I missing? I have read this posts about Websockets but I am a beginner at this scripting thing so I don't understand it all.

I have also added websocket.lua (a file from another post) in my user library in LM.


RE: Problems with javascript write to bus - admin - 03.05.2021

Line 19 is wrong, replace it with this:
Code:
localbus.init('http://192.168.10.111', 'admin:admin');



RE: Problems with javascript write to bus - Alexander - 03.05.2021

(03.05.2021, 10:09)admin Wrote: Line 19 is wrong, replace it with this:
Code:
localbus.init('http://192.168.10.111', 'admin:admin');

Hi, that worked like a charm.
Thank you very much Smile


RE: Problems with javascript write to bus - Alexander - 03.05.2021

Hi again,

Where in the code above should I put my write function? Can you give me an example?


RE: Problems with javascript write to bus - admin - 04.05.2021

Example:
Code:
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script src="http://192.168.10.111/apps/js/jquery.js.gz"></script>
  <script src="http://192.168.10.111/apps/js/localbus.js.gz"></script>
  <script src="http://192.168.10.111/scada/vis/busdecode.js.gz"></script>
</head>
<body>

<button id="example">Click to write</button>
<script>

$(function() {
  // listen to all groupwrite telegrams
  localbus.listen('groupwrite', function(event) {
    console.log(event);
  });

  localbus.init('http://192.168.10.111', 'admin:admin');

  $('#example').click(function() {
    localbus.write('0/0/10', true);
  });
});
</script>
</body>
</html>



RE: Problems with javascript write to bus - Alexander - 04.05.2021

(04.05.2021, 06:22)admin Wrote: Example:
Code:
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script src="http://192.168.10.111/apps/js/jquery.js.gz"></script>
  <script src="http://192.168.10.111/apps/js/localbus.js.gz"></script>
  <script src="http://192.168.10.111/scada/vis/busdecode.js.gz"></script>
</head>
<body>

<button id="example">Click to write</button>
<script>

$(function() {
  // listen to all groupwrite telegrams
  localbus.listen('groupwrite', function(event) {
    console.log(event);
  });

  localbus.init('http://192.168.10.111', 'admin:admin');

  $('#example').click(function() {
    localbus.write('0/0/10', true);
  });
});
</script>
</body>
</html>

Thank you, now I have something to work on Smile