Config mqtt-collection for Meteor: How to?

I’m trying to use @perak’s meteor-mqtt-collection package to connect to CloudMQTT, but am unsure about how to interpret the syntax for the mqttConnect(…) function parameters. I’m able to connect with my auth credentials using NodeJS, but not Meteor.

If you know how to configure this mqtt-collection package to access an MQTT broker, there are further details on my Stack Overflow post.

@interfusion investigating…

  1. did you try to specify protocol in the url (one of: ‘mqtt://’, ‘mqtts://’, ‘tcp://’, ‘tls://’, ‘ws://’, ‘wss://’) ?

  2. perak:mqtt-collection is using old version of mqtt npm package (1.2.0) - maybe that old version doesn’t support options (e.g. servers: [ ... ]) or something…?

OK, I successfully connected to cloudmqtt, this is my connection:

Sensors.mqttConnect('mqtt://m21.cloudmqtt.com', ['#'], {
	clientId: "123456",
	username: "my_username",
	password: "my_password"
});

Adding mqtt:// into URL did the trick.

Great. Thanks for the quick response Petar. :slight_smile:

:+1:

BTW, maybe “meteor kitchen” can help you in your journey with meteor and IoT:

http://www.meteorkitchen.com

IoT related examples:

http://generator-iot.meteor.com
http://generator-geiger.meteor.com

Also, you can write simple IoT app in English :slightly_smiling:

http://generator-human2machine.meteor.com

human2machine npm & docs: https://www.npmjs.com/package/human2machine

Enjoy! :slightly_smiling:

Hi Again @perak. I’ve been working more on this issue and am having troubles replicating your success connecting to the MQTT broker properly. In your code:

Sensors.mqttConnect('mqtt://m21.cloudmqtt.com', ['#'], {
	clientId: "123456",
	username: "my_username",
	password: "my_password"
});

CloudMQTT says they need traffic on port 12310, but it sounds like you got it working without the port identified. Unfortunately, that didn’t work for me so I’m using:

    MyGoals.mqttConnect("mqtt://m10.cloudmqtt.com", ['goals'], {
        insert: true,
        raw: true
      },
      { servers: [{ host: 'mqtt://m10.cloudmqtt.com', port: 12310 }],
        clientId: "uniqueID",
        username: "mqttClientUsername",
        password: "mqttClientPassword",
        clean:false
      });

My insert statement is just added to the button click events helper in the standard meteor create javascript file:

MyGoals.insert({
  topic: "goals", 
  message: "There were " + Session.get('counter') + " clicks.", 
  broadcast: true
});

My traffic does show up in MiniMongo, but never seems to hit CloudMQTT’s traffic console.
If I replace the ‘goals’ topic with the ‘#’ topic wildcard, I do see other users’ traffic entering my MiniMongo, but either way, my traffic never seems to hit CloudMQTT’s console.

Do you have any suggestions on how I might debug this?

How about: mqttConnect("mqtt://m21.cloudmqtt.com:12310" ..... ?

Thanks. Actually I had also hoped that might work, but unfortunately the app crashes with that URI format.

=> App running at: http://localhost:3000/
   Type Control-C twice to stop.

W20160304-10:15:58.500(-8)? (STDERR)
W20160304-10:15:58.500(-8)? (STDERR) events.js:72
W20160304-10:15:58.501(-8)? (STDERR)         throw er; // Unhandled 'error' event
W20160304-10:15:58.501(-8)? (STDERR)               ^
=> Exited with code: 8
W20160304-10:15:58.502(-8)? (STDERR) Error: Connection refused: Not authorized
W20160304-10:15:58.502(-8)? (STDERR)     at MqttClient._handleConnack (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\lib\client.js:665:9)
W20160304-10:15:58.503(-8)? (STDERR)     at MqttClient._handlePacket (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\lib\client.js:273:12)
W20160304-10:15:58.503(-8)? (STDERR)     at process (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\lib\client.js:196:12)
W20160304-10:15:58.503(-8)? (STDERR)     at Writable.writable._write (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\lib\client.js:206:5)
W20160304-10:15:58.504(-8)? (STDERR)     at doWrite (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:237:10)
W20160304-10:15:58.504(-8)? (STDERR)     at writeOrBuffer (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:227:5)
W20160304-10:15:58.504(-8)? (STDERR)     at Writable.write (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:194:11)
W20160304-10:15:58.504(-8)? (STDERR)     at write (_stream_readable.js:602:24)
W20160304-10:15:58.504(-8)? (STDERR)     at flow (_stream_readable.js:611:7)
W20160304-10:15:58.505(-8)? (STDERR)     at Socket.pipeOnReadable (_stream_readable.js:643:5)

I’ve switched over to Mosquitto’s test-broker which doesn’t need authentication and uses the standard MQTT port.

MyGoals.mqttConnect('mqtt://test.mosquitto.org',['goals'],{
  insert: true,
  raw: true
});

Everything is working. :slight_smile: Very impressive to see Meteor Collections and an MQTT broker working together!!! There are so many possibilities enabled by combining Meteor with IoT. Kudos on the package to @perak!

So it looks like the only trouble is associated with setting the port and/or the auth credentials.

Hi Perak,

If I want to send some message using mqtt. How can we do that?
I’m also new in this. And implemented according to your example given in meteor kitchen.
But not getting how message will come in my project :cry:

Regards,
Pooja