rm priv
This commit is contained in:
parent
af025d5625
commit
c42673ae79
|
@ -1,64 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>MQTT over WebSocket</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>MQTT Over WebSocket</h1>
|
||||
<div id="connect">
|
||||
<button id="btnConn">Connect</button>
|
||||
State: <span id="connstate" style="font-weight:bold;"></span>
|
||||
</div>
|
||||
<script src="./mqttws31.js"></script>
|
||||
<script>
|
||||
|
||||
var ws;
|
||||
if (!window.WebSocket) {
|
||||
alert("WebSocket not supported by this browser");
|
||||
}
|
||||
function $(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
// Create a client instance
|
||||
client = new Paho.MQTT.Client(location.hostname, Number(location.port), "/mqtt", "clientId");
|
||||
|
||||
// set callback handlers
|
||||
client.onConnectionLost = onConnectionLost;
|
||||
client.onMessageArrived = onMessageArrived;
|
||||
|
||||
function go() {
|
||||
// connect the client
|
||||
client.connect({onSuccess:onConnect});
|
||||
}
|
||||
|
||||
// called when the client connects
|
||||
function onConnect() {
|
||||
alert("connected"),
|
||||
$('connstate').innerHTML = 'CONNECTED';
|
||||
// Once a connection has been made, make a subscription and send a message.
|
||||
console.log("onConnect");
|
||||
client.subscribe("/World");
|
||||
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);
|
||||
}
|
||||
|
||||
$('btnConn').onclick = function(event) {
|
||||
go(); return false;
|
||||
};
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
2143
priv/www/mqttws31.js
2143
priv/www/mqttws31.js
File diff suppressed because it is too large
Load Diff
|
@ -1,59 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>MQTT Over Mochiweb websocket</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>MQTT Over Mochiweb websocket</h1>
|
||||
|
||||
<div id="connect">
|
||||
<button id="btnConn">Connect</button>
|
||||
State: <span id="connstate" style="font-weight:bold;"></span>
|
||||
</div>
|
||||
<br/><i>Protip: open your javascript error console, just in case..</i><br/>
|
||||
<hr/>
|
||||
<div id="connected">
|
||||
<form id="sendForm">
|
||||
<input id="phrase" type="text"/>
|
||||
<input id="btnSend" class="button" type="submit" name="connect"
|
||||
value="Send"/>
|
||||
</form>
|
||||
</div>
|
||||
<hr/>
|
||||
<div id="msgs"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var ws;
|
||||
if (!window.WebSocket) {
|
||||
alert("WebSocket not supported by this browser");
|
||||
}
|
||||
function $(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
function go() {
|
||||
ws = new WebSocket("ws://" + location.host + "/mqtt");
|
||||
ws.onopen = function () {
|
||||
$('connstate').innerHTML = 'CONNECTED';
|
||||
}
|
||||
ws.onclose = function () {
|
||||
$('connstate').innerHTML = 'CLOSED';
|
||||
}
|
||||
ws.onmessage = function (e) {
|
||||
var p = document.createElement('pre');
|
||||
p.appendChild(document.createTextNode(e.data));
|
||||
$('msgs').appendChild(p);
|
||||
}
|
||||
}
|
||||
$('sendForm').onsubmit = function (event) {
|
||||
var p = $('phrase');
|
||||
ws.send(p.value);
|
||||
p.value='';
|
||||
return false;
|
||||
}
|
||||
$('btnConn').onclick = function(event) {
|
||||
go(); return false;
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue