Skip to content

Instantly share code, notes, and snippets.

@hardillb hardillb/SendMessage.html
Last active Oct 7, 2016

Embed
What would you like to do?
<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
You can’t perform that action at this time.