How to use the mqtt.createClient function in mqtt

To help you get started, we’ve selected a few mqtt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stormboy / whims / test / test_meemfactory.js View on Github external
var facet = require("../lib/facet");
var mqtt = require("mqtt");

var basic = require("../lib/meems/basic");

var namespaces = {
		"basic" : basic
};

// test creating

console.log("ccreating BinaryScheduler");
var binaryScheduler = new basic.BinaryScheduler({});

// test the MeemFactory
var mqttClient = mqtt.createClient(1883, '192.168.0.23');
var meemBus = new MeemBus(mqttClient);
var mf = new MeemFactory(namespaces, meemBus);

console.log("using factory to create BinaryTimer");

var properties = {};
var meemDef = {
		id : "123456789ABCDEF",
		type: "basic.BinaryTimer",
		properties: properties,
};

var meem = mf.create(meemDef);
github octoblu / meshblu / lib / setupMqttClient.js View on Github external
// Handle MQTT Messages
  try{

    var mqttConfig = config.mqtt || {};
    var mqttsettings = {
      keepalive: 1000, // seconds
      protocolId: 'MQIsdp',
      protocolVersion: 3,
      //clientId: 'skynet',
      username: 'skynet',
      password: process.env.MQTT_PASS || mqttConfig.skynetPass
    };
    var mqttPort = process.env.MQTT_PORT || mqttConfig.port || 1833;
    var mqttHost = process.env.MQTT_HOST || mqttConfig.host || 'localhost';
    client = mqtt.createClient(mqttPort, mqttHost, mqttsettings);
  } catch(e){
    console.error('no mqtt server found', e);
  }

  return client;

};
github stormboy / node-upnp-controlpoint / examples / wemo-mqtt.js View on Github external
WemoBinaryMqtt.prototype.init = function(options) {
	var self = this;
	
	if (TRACE) {
		console.log("initialise MQTT connection");
	}
	
	var clientId = crypto.randomBytes(24).toString("hex");
	
	// connect to MQTT service
	this.mqttClient = mqtt.createClient(options.port, options.host, {
		keepalive: 10000,
		client : clientId
	});
	
	// add handlers to MQTT client
	this.mqttClient.on('connect', function() {
		if (TRACE) {
			console.log('MQTT sessionOpened');
		}
		self.subscribe();	// subscribe to control and request topics
	});
	this.mqttClient.on('close', function() {
		if (TRACE) {
			console.log('MQTT close');
		}
	});
github mcollina / ponte / benchmark / many-to-one / http-to-mqtt.js View on Github external
var mqtt = require("mqtt")
  , request = require("superagent")
  , total = 500
  , sent = 0
  , received = 0
  , listener = mqtt.createClient()
  , print = function(text) {
              process.stdout.write(text + "\n");
            }
  , start = null
  , publish = function() {
                  console.error("client connected, sending the message");
                  start = Date.now();
                  
                  for (i = 0; i < total; i++)
                    request
                        .put('http://localhost:3000/topics/hello')
                        .send("world")
                        .end(function(error, res){
                          //if (sent++ % (total / 10)) {
                          //  console.error("sent", sent)
                          //}
github stormboy / whims / lib / meemserver.js View on Github external
var MeemServer = function(options) {
	this.subsystems = {};
	
	this.meemStore = new MeemStore(options ? options.store : null);
	
	this.mqttHost = options.mqttHost || "127.0.0.1";	// host for the MQTT server to connect to
	this.mqttPort = options.mqttPort || 1833;			// port for the MQTT server
	this.clientId = "meem_" + crypto.randomBytes(8).toString('hex');

	this.mqttClient = mqtt.createClient(this.mqttPort, this.mqttHost, {
		keepalive: 10000,
		client : clientId
	});

	this.meemBus = new MeemBus(mqttClient);
};
github erikhazzard / realtime-chat-benchmarks / mqtt / test-apollo / client.js View on Github external
var mqtt = require('mqtt')


client = mqtt.createClient(61613, 'localhost', {username: "admin", password: "password"});

client.subscribe('presence');
client.publish('presence', 'Hello mqtt');

client.on('message', function (topic, message) {
  console.log(message);
});



setInterval(function(d, i){
  client.publish('presence', 'Hello mqtt');
}, 1000);
github mcollina / ponte / test / mqtt_spec.js View on Github external
it("should allow a client to publish and subscribe", function(done) {
    var client = mqtt.createClient(settings.mqtt.port);
    client
      .subscribe("/hello")
      .publish("/hello", "world")
      .on("message", function(topic, payload) {
        expect(topic).to.eql("/hello");
        expect(payload).to.eql("world");
        done();
      });
  });
github mcollina / ponte / test / mqtt_spec.js View on Github external
it("should emit an 'updated' event after a publish", function(done) {

    var client = mqtt.createClient(settings.mqtt.port);
    client.publish("/hello", "world",
                   { retain: true, qos: 1 },
                   function() {
      client.end();
    });

    instance.on('updated', function(resource, value) {
      expect(resource).to.eql("/hello");
      expect(value).to.eql(new Buffer("world"));
      done();
    });
  });
});
github wolfeidau / mqtt-rpc / test / combined.js View on Github external
it('server respond to a request from the client', function (done) {

    var mqttclient = mqtt.createClient();

    var prefix = "$RPC/time3";

    var server = mqttrpc.server(mqttclient);

    server.provide(prefix, 'localtime', function (args, cb) {
      debug('localtime');
      cb(null, new Date());
    });

    var client = mqttrpc.client(mqttclient);

    client.callRemote(prefix, 'localtime', {}, function (err, data) {
      debug('callRemote', err, data);
      expect(data).to.exist;
      expect(err).to.not.exist;
github enableiot / iotkit-agent / lib / mqtt-connector / connector.js View on Github external
me.connect = function(done) {
        var retries = 0;
        try {
            if (me.secure) {
                me.logger.info("Trying with Secure Connection to", me.host, ":", me.port, "with ", me.tlsArgs);
                me.client = mqtt.createSecureClient(me.port, me.host, me.tlsArgs);
            }
            else {
                me.logger.info("Non Secure Connection to ", me.host, ":", me.port);
                me.client = mqtt.createClient(me.port, me.host);
            }
        } catch(e) {
            done(new Error("Connection Error", 1002));
            return;
        }
        function waitForConnection() {
            if (!me.client.connected) {
                retries++;
                me.logger.info("Waiting # ", retries);
                if (retries < me.max_retries) {
                    setTimeout(waitForConnection, 500);
                } else {
                    me.logger.info('MQTTConnector: Error Connecting to ', me.host, ':', me.port);
                    done(new Error("Connection Error", 1001));
                }
                return false;