Logic Machine Forum
Listen to bus on website - 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: Listen to bus on website (/showthread.php?tid=525)

Pages: 1 2


Listen to bus on website - RSV4 - 23.12.2016

Hi all,

On my intranet I was listening to the KNX Bus via long polling and ajax requests using

/cgi-bin/scada-vis/general/objects-update.cgi


Since updating to firmware 20160927, this no longer works, I haven't had time to dig into it yet. Is there a new state-of-the-art way to listen to the bus which will update values on a webpage without reloading the page (i.e. to update a field containing a temperature value, or switch status, etc.)

Best regards,
Robin


RE: Listen to bus on website - Erwin van der Zwart - 23.12.2016

Hi Robin,

Long polling is changed to websocket connection.

Never done external from other server but should be possible i guess.

Lets wait what admin say (:


RE: Listen to bus on website - RSV4 - 23.12.2016

Hi Erwin
Thank you! Therefore we'll wait for the admin.


RE: Listen to bus on website - admin - 24.12.2016

Long polling is still there, but only for the admin part, so as a temporary solution you can access it via /scada-main/objects/update
I'll prepare a WebSocket example later on.


RE: Listen to bus on website - RSV4 - 27.12.2016

Websocket example would be fantastic!


RE: Listen to bus on website - savaskorkmaz - 28.12.2016

Hello , I have a question. Should websocket use a different port http port ? Or can we use same TCP port ?

Regards


RE: Listen to bus on website - admin - 28.12.2016

Same port is used for both WebSockets and standard HTTP requests.


RE: Listen to bus on website - ceyhanc - 28.12.2016

Hi All,

Can anyone share a Websocket example which is working with same HTTP port ?

Thanks
BR
Ceyhan


RE: Listen to bus on website - admin - 03.01.2017

Here's a short example for how it can work via WebSocket, the problem is that this example requires latest beta firmware and work won't on 2016.09.30.
Code:
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script src="http://192.168.1.9/apps/js/jquery.js.gz"></script>
  <script src="http://192.168.1.9/apps/js/localbus.js.gz"></script>
  <script src="http://192.168.1.9/scada/vis/busdecode.js.gz"></script>
</head>
<body>
<script>
$(function() {
  // listen to all groupwrite telegrams
  localbus.listen('groupwrite', function(event) {
    console.log(event);
  });

  // listen to a single object
  localbus.listen('object', '1/1/1', function(value) {
    console.log(value);
  });

  localbus.init('http://192.168.1.9');
});
</script>
</body>
</html>

(28.12.2016, 12:29)ceyhanc Wrote: Can anyone share a Websocket example which is working with same HTTP port ?
Can you explain which kind of data do you want to send over websocket?


RE: Listen to bus on website - ceyhanc - 03.01.2017

(03.01.2017, 11:26) pid=\2913' Wrote:Here's a short example for how it can work via WebSocket, the problem is that this example requires latest beta firmware and work won't on 2016.09.30.
Code:
<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <script src="http://192.168.1.9/apps/js/jquery.js.gz"></script>
 <script src="http://192.168.1.9/apps/js/localbus.js.gz"></script>
 <script src="http://192.168.1.9/scada/vis/busdecode.js.gz"></script>
</head>
<body>
<script>
$(function() {
 // listen to all groupwrite telegrams
 localbus.listen('groupwrite', function(event) {
   console.log(event);
 });

 // listen to a single object
 localbus.listen('object', '1/1/1', function(value) {
   console.log(value);
 });

 localbus.init('http://192.168.1.9');
});
</script>
</body>
</html>

(28.12.2016, 12:29)ceyhanc Wrote: Can anyone share a Websocket example which is working with same HTTP port ?
Can you explain which kind of data do you want to send over websocket?

I need to ask, when localbus.init runs;
1. Does websocket server runs at same ip/port with visualisation ?
2. when we try to listen 1 object; will server push to chaged data or actual data to client ?
3. can we listen multiple objects with [ localbus.listen('object', ] notation ?


We want to take some binary objects true/false values to our native Android/IOS app.
Our aims;
1. We use several alarm objects and get informations of them fastly (like TCP socket communication)
2. We want to server will push to alarm info to client.
3. We want to do all communications with one port. (All LM Visualisation and this information)
4. We dont want to use JSON/XML  (It requires reconnect to server for getting informations every 5 sec.)


Thanks
Ceyhan


RE: Listen to bus on website - RSV4 - 03.01.2017

(03.01.2017, 11:26)admin Wrote: Here's a short example for how it can work via WebSocket, the problem is that this example requires latest beta firmware and work won't on 2016.09.30.

Thanks.

1. Will everything else keep working if I upgrade to the latest beta firmware?
2. Will the websocket code still run in the next official firmware release? (I do not want to reprogram my intranet with every release)

3.
Quote:Long polling is still there, but only for the admin part, so as a temporary solution you can access it via /scada-main/objects/update
Can't get this work, what is the name of the .cgi file in the folder you mentioned?
Many thanks!


RE: Listen to bus on website - admin - 03.01.2017

Quote:1. Does websocket server runs at same ip/port with visualisation ?
Yes

Quote:2. when we try to listen 1 object; will server push to chaged data or actual data to client ?
All bus telegrams are pushed no matter how many objects you listen to

Quote:3. can we listen multiple objects with [ localbus.listen('object', ] notation ?
You can have many listeners for each object or use a single telegram listener and filter event by dst group address param

Quote:1. Will everything else keep working if I upgrade to the latest beta firmware?
Nobody knows as it's not fully tested yet Smile

Quote:2. Will the websocket code still run in the next official firmware release? (I do not want to reprogram my intranet with every release)
Yes

Quote:Can't get this work, what is the name of the .cgi file in the folder you mentioned?
The path is http://LM_IP/scada-main/objects/update


RE: Listen to bus on website - RSV4 - 03.01.2017

(03.01.2017, 15:48)admin Wrote:
Quote:The path is http://LM_IP/scada-main/objects/update

Thanks. But whats the name of the .cgi file? Is it still objects-update.cgi (http://LM_IP/scada-main/objects/update/objects-update.cgi)? I always got a 404...

Edit: oh- I might have had a /cgi in my path. Will check tonight.

Does websocket also work the other way round, e.g. what is the code to send a grp.write from html/js/jquery?


RE: Listen to bus on website - RSV4 - 03.01.2017

Tried to fix the polling function, no success. Can you please take at look at this:

Code:
poll = function() {
  $.ajax({
    //url: 'http://10.0.x.xx/cgi-bin/scada-vis/general/objects-update.cgi',
     url: 'http://10.0.x.xx/scada-main/objects/update/objects-update.cgi',
    type: 'GET',
    data: { upd: upd },
    error: check,
    success: check,
    timeout: 60 * 1000
  });
};

Code:
function read() {
 $.ajax({
   // url: host + '/cgi-bin/scada-vis/general/request.cgi?_module=objects&_action=main',
    url: host + '/scada-main/objects/update/request.cgi?_module=objects&_action=main',
   type: 'POST',
   dataType: 'json',
   data: { updatetime: time, skiptags: 1 },
   error: poll,
   success: update,
   timeout: 15 * 1000
 });
}

I tried altering the path as described a few posts above, did not work, see my code snippets above. I also tried adding /cgi-bin/ at the beginning of the altered path, also no success. I'd really like to fix this that my site is up and running again and switch to websocket as soon as the beta firmware is final. Thank you!


RE: Listen to bus on website - admin - 04.01.2017

First url should be:
http://10.0.x.xx/scada-main/objects/update

Second one should be:
http://10.0.x.xx/scada-main/objects/main


RE: Listen to bus on website - admin - 04.01.2017

As for sending values from client you can use these functions (keep in mind that only group addresses can be used here, not object names):
Code:
localbus.write('1/1/1', true);  // same as grp.write('1/1/1', true)
localbus.update('1/1/2', 42); // same as grp.update('1/1/2', 42)



RE: Listen to bus on website - RSV4 - 04.01.2017

(04.01.2017, 07:24)admin Wrote: First url should be:
http://10.0.x.xx/scada-main/objects/update

Second one should be:
http://10.0.x.xx/scada-main/objects/main

This does not work. I get a Cross origin error in the web console for http://10.0.x.x/scada-main/objects/update/objects-update.cgi?upd=0. Reason "CORS-Header 'Access-Control-Allow-Origin' missing". Ideas?


(04.01.2017, 09:01)admin Wrote: As for sending values from client you can use these functions (keep in mind that only group addresses can be used here, not object names):
Code:
localbus.write('1/1/1', true);  // same as grp.write('1/1/1', true)
localbus.update('1/1/2', 42); // same as grp.update('1/1/2', 42)

Great, looking forward to that firmware!


RE: Listen to bus on website - admin - 05.01.2017

Unfortunately it won't work with current FW due to browser security checks. I can provide beta FW for you test if you want.


RE: Listen to bus on website - RSV4 - 05.01.2017

That would be great, can you please send the beta firmware to the email I am registered here in the forum? Furthermore, do the packages for MySQL work on the beta firmware? Many thanks!


RE: Listen to bus on website - admin - 05.01.2017

Which device do you need the FW for? MySQL will work, but you will have to re-install the packages, because custom packages are not kept during FW upgrade.