-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3d19a38
Showing
4 changed files
with
1,982 additions
and
0 deletions.
There are no files selected for viewing
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
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"; |
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
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> |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.