This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

connect MQTT Broker from web and inside LM
#3
(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>
Reply


Messages In This Thread
RE: connect MQTT Broker from web and inside LM - by Hadeel - 02.08.2022, 14:15

Forum Jump: