Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.25 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="fr-fr">
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>Frugal Prototype</title>
  6.     <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
  7.   </head>
  8.   <body>
  9.     <!-- page content -->
  10.   </body>
  11.  
  12. <script>
  13. // Create a client instance
  14. client = new Paho.MQTT.Client("127.0.0.1", 61614, "clientId");
  15.  
  16. // set callback handlers
  17. client.onConnectionLost = onConnectionLost;
  18. client.onMessageArrived = onMessageArrived;
  19.  
  20. // connect the client
  21. client.connect({onSuccess:onConnect});
  22.  
  23.  
  24. // callback au succes de la connexion
  25. function onConnect() {
  26.   // Once a connection has been made, make a subscription and send a message.
  27.   console.log("Connexion réussie");
  28.   client.subscribe("frugalprototype");
  29.   message = new Paho.MQTT.Message("Hello");
  30.   message.destinationName = "World";
  31.   client.send(message);
  32. }
  33.  
  34. // called when the client loses its connection
  35. function onConnectionLost(responseObject) {
  36.   if (responseObject.errorCode !== 0) {
  37.     console.log("onConnectionLost:"+responseObject.errorMessage);
  38.   }
  39. }
  40.  
  41. // called when a message arrives
  42. function onMessageArrived(message) {
  43.   console.log("onMessageArrived:"+message.payloadString);
  44. }
  45.  
  46. </script>
  47.  
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement