ALLTERCO / shelly-script-examples

Shelly Scripts for Gen2 Shelly devices
Apache License 2.0
199 stars 55 forks source link

MQTT.setConnectHandler() #40

Open Jeandhom opened 1 year ago

Jeandhom commented 1 year ago

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

taulfsime commented 1 year ago

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