Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <script
- src="https://code.jquery.com/jquery-3.1.1.min.js"
- integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
- crossorigin="anonymous"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
- <script>
- // Create a client instance
- client = new Paho.MQTT.Client('10.0.3.12', 8000, "", "clientIddasads");
- // set callback handlers
- client.onConnectionLost = onConnectionLost;
- client.onMessageArrived = onMessageArrived;
- // connect the client
- client.connect({onSuccess:onConnect, userName:"aisdn", password:"aisdn99"});
- // called when the client connects
- function onConnect() {
- // Once a connection has been made, make a subscription and send a message.
- console.log("onConnect");
- client.subscribe("TempSensor");
- message = new Paho.MQTT.Message("Hello");
- message.destinationName = "TempSensor";
- client.send(message);
- }
- // called when the client loses its connection
- function onConnectionLost(responseObject) {
- if (responseObject.errorCode !== 0) {
- console.log("onConnectionLost:"+responseObject.errorMessage);
- }
- }
- // called when a message arrives
- function onMessageArrived(message) {
- $('#poruka').val(message.payloadString);
- }
- $(document).ready(function () {
- $(document).on('change','#control',function () {
- message = new Paho.MQTT.Message($(this).val());
- message.destinationName = "TempSensorControl";
- client.send(message);
- })
- })
- </script>
- </head>
- <body>
- <input id="poruka" type="text" name="fname">
- <select id="control">
- <option value="R1=ON">R1=ON</option>
- <option value="R1=OFF">R1=OFF</option>
- </select>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement