ALLTERCO/shelly-script-examples

MQTT.setConnectHandler()

Opened this issue · 1 comments

Hi,
Is there a way, per script, to create a new idClient, other than that of the module which houses the script, and to indicate its keepAlive, willMessage, willTopic, etc...
The MQTT.setConnectHandler(callback, callback_arg) function, can it do this job?
Can you provide an example of using this function?
Best regards

This function registers a callback that to be called once the mqtt connection is established. The 'callback_args' parameter will be passed to the callback when it's called.
You should be able to use mqtt.publish to send data to whatever topic you want.

Check this https://github.com/ALLTERCO/shelly-script-examples/blob/main/mqtt-switch-status-announce.js