Skip to content

Instantly share code, notes, and snippets.

@hardillb
Last active October 7, 2016 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardillb/8cc20a0df2431e4cda6c7739f2a0e670 to your computer and use it in GitHub Desktop.
Save hardillb/8cc20a0df2431e4cda6c7739f2a0e670 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Push button, send message</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
</head>
<body>
<button onclick="sendMessage();">Push Me</button>
<script type="text/javascript">
var clientID = "ID-" + Math.round(Math.random() * 1000);
var client = new Paho.MQTT.Client(location.hostname, Number(location.port), clientID);
client.connect({onSuccess:onConnect});
function onConnect() {
console.log("connected");
}
function sendMessage() {
console.log("sending");
var message = new Paho.MQTT.Message("Hello");
message.destinationName = "World";
client.send(message);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment