Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="fr-fr">
- <head>
- <meta charset="utf-8">
- <title>Frugal Prototype</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
- </head>
- <body>
- <!-- page content -->
- </body>
- <script>
- // Create a client instance
- client = new Paho.MQTT.Client("127.0.0.1", 61614, "clientId");
- // set callback handlers
- client.onConnectionLost = onConnectionLost;
- client.onMessageArrived = onMessageArrived;
- // connect the client
- client.connect({onSuccess:onConnect});
- // callback au succes de la connexion
- function onConnect() {
- // Once a connection has been made, make a subscription and send a message.
- console.log("Connexion réussie");
- client.subscribe("frugalprototype");
- message = new Paho.MQTT.Message("Hello");
- message.destinationName = "World";
- 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) {
- console.log("onMessageArrived:"+message.payloadString);
- }
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement