Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Title</title>
  6.     <script
  7.             src="https://code.jquery.com/jquery-3.1.1.min.js"
  8.             integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  9.             crossorigin="anonymous"></script>
  10.     <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
  11.     <script>
  12.         // Create a client instance
  13.         client = new Paho.MQTT.Client('10.0.3.12', 8000, "", "clientIddasads");
  14.  
  15.         // set callback handlers
  16.         client.onConnectionLost = onConnectionLost;
  17.         client.onMessageArrived = onMessageArrived;
  18.  
  19.         // connect the client
  20.         client.connect({onSuccess:onConnect, userName:"aisdn", password:"aisdn99"});
  21.  
  22.  
  23.         // called when the client connects
  24.         function onConnect() {
  25.             // Once a connection has been made, make a subscription and send a message.
  26.             console.log("onConnect");
  27.             client.subscribe("TempSensor");
  28.             message = new Paho.MQTT.Message("Hello");
  29.             message.destinationName = "TempSensor";
  30.             client.send(message);
  31.         }
  32.  
  33.         // called when the client loses its connection
  34.         function onConnectionLost(responseObject) {
  35.             if (responseObject.errorCode !== 0) {
  36.                 console.log("onConnectionLost:"+responseObject.errorMessage);
  37.             }
  38.         }
  39.  
  40.         // called when a message arrives
  41.         function onMessageArrived(message) {
  42.             $('#poruka').val(message.payloadString);
  43.         }
  44.  
  45.         $(document).ready(function () {
  46.             $(document).on('change','#control',function () {
  47.                 message = new Paho.MQTT.Message($(this).val());
  48.                 message.destinationName = "TempSensorControl";
  49.                 client.send(message);
  50.             })
  51.         })
  52.     </script>
  53. </head>
  54. <body>
  55. <input id="poruka" type="text" name="fname">
  56. <select id="control">
  57.     <option value="R1=ON">R1=ON</option>
  58.     <option value="R1=OFF">R1=OFF</option>
  59. </select>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement