Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmens committed Jul 2, 2014
0 parents commit 3d19a38
Show file tree
Hide file tree
Showing 4 changed files with 1,982 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
websocketserver = '127.0.0.1';
websocketport = 9001;
topic = '#';
useTLS = false;
// username = null;
// password = null;
username = "jjolie";
password = "aa";
74 changes: 74 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>Mosquitto Websockets</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="mqttws31.js" type="text/javascript"></script>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="config.js" type="text/javascript"></script>

<script type="text/javascript">
var client = new Messaging.Client(
websocketserver,
websocketport,
"web_" + parseInt(Math.random() * 100,
10));

client.onConnectionLost = function (responseObject) {
$('#status').val("connection lost: " + responseObject.errorMessage);

};

client.onMessageArrived = function (message) {
var topic = message.destinationName;
var payload = message.payloadString;

$('#ws').prepend('<li>' + topic + ' = ' + payload + '</li>');
};

var options = {
timeout: 3,
useSSL: useTLS,
onSuccess: function () {
$('#status').val('Connected to ' + websocketserver + ':' + websocketport);
// Connection succeeded; subscribe to our topic
client.subscribe(topic, {qos: 0});
$('#topic').val(topic);

},
onFailure: function (message) {
$('#status').val("Connection failed: " + message.errorMessage);

}
};

function init() {
/* Connect to MQTT broker */
if (username != null) {
options.userName = username;
options.password = password;
}
console.log("TLS = " + useTLS + " username=" + username + " password=" + password);
client.connect(options);
}

$(document).ready(function() {
init();
});

</script>
</head>
<body>
<h1>Mosquitto Websockets</h1>
<div>
Subscribed to <input type='text' id='topic' /> Status: <input type='text' id='status' size="80" />
<h3>Messages</h3>

<ul id='ws' style="font-family: 'Courier New', Courier, monospace;">
</ul>
</div>

</div>
</body>
</html>
19 changes: 19 additions & 0 deletions jquery.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 3d19a38

Please sign in to comment.