Mqtt.js: User name and password for MQTT connection

Created on 2 Jul 2015  路  4Comments  路  Source: mqttjs/MQTT.js

My MQTT server requires user name and password for connection. For example,

mosquitto_sub -t '#' -u 'username' -P 'password'

I am unable to see any username/password in the examples and the source code. Wonder if anyone can give me some help.

Thanks,
Jingzhao

Most helpful comment

I tested the following options.

    client = mqtt.connect({
        host: 'www.example.com',
        port: 1883,
        username: 'username',
        password: 'password'
    });

Things work properly.

All 4 comments

You can pass username and password to mqtt.connect, as they are part of the CONNECT packet. I will leave this open, and it is probably worth to add them to the README.

Would you like to send a PR?

I tested the following options.

    client = mqtt.connect({
        host: 'www.example.com',
        port: 1883,
        username: 'username',
        password: 'password'
    });

Things work properly.

Already submitted a PR.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcollina picture mcollina  路  8Comments

markcnunes picture markcnunes  路  7Comments

stozk picture stozk  路  3Comments

DavidMG01 picture DavidMG01  路  4Comments

goliatone picture goliatone  路  4Comments