Last active
October 7, 2016 14:27
-
-
Save hardillb/8cc20a0df2431e4cda6c7739f2a0e670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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