Skip to content

Commit

Permalink
Merge pull request #1 from ckrey/master
Browse files Browse the repository at this point in the history
[NEW] use optional path argument for websocket URL
  • Loading branch information
JP Mens committed Jan 4, 2016
2 parents 24ca321 + 88ee493 commit 050c187
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 8 additions & 0 deletions config.js
Expand Up @@ -8,4 +8,12 @@ username = null;
password = null;
// username = "jjolie";
// password = "aa";

// path as in "scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]"
// defaults to "/mqtt"
// may include query and fragment
//
// path = "/mqtt";
// path = "/data/cloud?device=12345";

cleansession = true;
18 changes: 11 additions & 7 deletions index.html
Expand Up @@ -13,11 +13,15 @@
var reconnectTimeout = 2000;

function MQTTconnect() {
mqtt = new Paho.MQTT.Client(
host,
port,
"web_" + parseInt(Math.random() * 100,
10));
if (typeof path == "undefined") {
path = '/mqtt';
}
mqtt = new Paho.MQTT.Client(
host,
port,
path,
"web_" + parseInt(Math.random() * 100, 10)
);
var options = {
timeout: 3,
useSSL: useTLS,
Expand All @@ -36,12 +40,12 @@
options.userName = username;
options.password = password;
}
console.log("Host="+ host + ", port=" + port + " TLS = " + useTLS + " username=" + username + " password=" + password);
console.log("Host="+ host + ", port=" + port + ", path=" + path + " TLS = " + useTLS + " username=" + username + " password=" + password);
mqtt.connect(options);
}

function onConnect() {
$('#status').val('Connected to ' + host + ':' + port);
$('#status').val('Connected to ' + host + ':' + port + path);
// Connection succeeded; subscribe to our topic
mqtt.subscribe(topic, {qos: 0});
$('#topic').val(topic);
Expand Down

0 comments on commit 050c187

Please sign in to comment.