Logic Machine Forum
connect MQTT Broker from web and inside LM - 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: connect MQTT Broker from web and inside LM (/showthread.php?tid=4170)



connect MQTT Broker from web and inside LM - Hadeel - 02.08.2022

I am trying to use LM broker app and publish/subscribe to it from webpage.
From the webpage I use websocket so the broker should open the port 8080 or 8081...
Also I need to prepare resident script to publish any change in KNX network so  the broker should also have port 1883 or 8883.

Am I able to open all of these ports with LM broker app?


RE: connect MQTT Broker from web and inside LM - Daniel - 02.08.2022

The broker talks only via MQTT so you only need port 1883 or 8883. You don't have to open anything on LM just make sure nothing else is blocking it on the way as router or some firewall.


RE: connect MQTT Broker from web and inside LM - Hadeel - 02.08.2022

(02.08.2022, 13:55)Daniel Wrote: The broker talks only via MQTT so you only need port 1883 or 8883. You don't have to open anything on LM just make sure nothing else is blocking it on the way as router or some firewall.

Thank you Daniel!

Okay, this is the html code I uploaded on the public directory of LM but it does not work... do you see anything strange ?

Code:
<html>
<head>
  <script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<meta charset="utf-8">
<title>MQTT TEST</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
<script>
$(function(){

   let client = mqtt.connect('ws://127.0.0.1:1883');
   let topic = "floor1/room1"
   let msg = '{"alias": "1/1/3", "value": 10}'

   client.subscribe(topic);
   client.publish(topic, msg);

   client.on('message', function (topic, message) { // message is Buffer
   console.log(message.toString());
});
});
</script>
</head>
<body>
</body>
</html>



RE: connect MQTT Broker from web and inside LM - admin - 02.08.2022

LM broker does not have websocket support. 127.0.0.1 in this case will try to connect to the client itself not to LM.

You don't need MQTT to access objects, you can use this: https://forum.logicmachine.net/showthread.php?tid=525&pid=2913#pid2913


RE: connect MQTT Broker from web and inside LM - Hadeel - 02.08.2022

Thank you , admin !
Never expected this way !

Where do I get the package of js/localbus.js.gz and scada/vis/busdecode.js.gz ?
Are there already in LM ?


RE: connect MQTT Broker from web and inside LM - admin - 02.08.2022

It's built-in. Same files are used by visualization and Mosaic.


RE: connect MQTT Broker from web and inside LM - Hadeel - 02.08.2022

Wow Idea

Yes it actually worked ! 

You guys are genius, LM is amazing !

Thank you admin and Daniel  Smile