Skip to content

Instantly share code, notes, and snippets.

@bastisk
Created December 10, 2015 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastisk/54ca64874c93cfb5b294 to your computer and use it in GitHub Desktop.
Save bastisk/54ca64874c93cfb5b294 to your computer and use it in GitHub Desktop.
client undefined
var mosca = require('mosca');
var mqtt = require('mqtt');
var client = mqtt.createClient(1883, "localhost", {username: "user", password: "pass"});
var moscaSettings = {
port: 1883,
}
var server = new mosca.Server(moscaSettings);
server.on('ready', setup);
server.on('clientConnected', function (client) {
console.log(client);
});
server.on('published', function (packet, client) {
console.log(client);
});
client.on('connect', function () {
client.subscribe('stuff');
});
function setup() {
server.authenticate = authenticate;
}
var authenticate = function (client, username, password, callback) {
var connectiona = {test: "test"};
client.connectiona = connectiona;
client.user = username;
authorized = true;
callback(null, authorized);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment