danielwippermann / resol-vbus-toolbox

A scripting environment to interact with the RESOL VBus.
MIT License
1 stars 0 forks source link

Does scripts/mqtt-publisher.js, support authentication with user and password? #2

Closed FollowTheWizard closed 11 months ago

FollowTheWizard commented 11 months ago

Hi i have another question :)

i did not see any user or password info in the scripts/mqtt file.

Can you let me know if that is supported or maybe ideally provide a config examples how to send the vbus data to the mqtt broker that needs a user with password?

The text log is working nicly, so the vbus communication seems to be stable.

the publishing to mqtt would me my final step :=)

thanks in advance

danielwippermann commented 11 months ago

Hi @FollowTheWizard !

The MQTT module used by the toolbox supports providing username and password as part of the URL as long as both conform to the rules for being suitable in a URL:

mqtt://<user>:<password>@<host>

So this for example works:

mqtt://user:secret@127.0.0.1

Alternatively I have just now pushed a change to the mqtt-publisher script that adds support for passing additional options to the MQTT module used. This should also allow usernames and passwords that are not suitable for use inside a URL:

...
    // URL to connect to the MQTT broker.
    url: 'mqtt://127.0.0.1',

    // Additional options used to create the MQTT client. See
    // https://github.com/mqttjs/MQTT.js#client for details.
    mqttClientOptions: {
        username: 'user',
        password: 's3cr3t@:/',
    },

    // Publish interval in milliseconds.
    interval: 10000,
...

Best regards, Daniel