Advertisement
cymplecy

mqtt

Oct 7th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.79 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <title>Push button, send message</title>
  4.       <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
  5.   </head>
  6.   <body>
  7.     <button onclick="sendMessage();">Push Me</button>
  8.     <script type="text/javascript">
  9.       var clientID = "ID-" + Math.round(Math.random() * 1000);
  10.       var client = new Paho.MQTT.Client("192.168.0.23", "1883", clientID);
  11.  
  12.       client.connect({onSuccess:onConnect});
  13.  
  14.       function onConnect() {
  15.         console.log("connected");
  16.       }
  17.  
  18.       function sendMessage() {
  19.         console.log("sending");
  20.         var message = new Paho.MQTT.Message("qplaypause");
  21.         message.destinationName = "cycy42/skyq";
  22.         client.send(message);
  23.       }
  24.  
  25.     </script>
  26.   </body>
  27. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement