MQTT plugin sample

Hi,

in MQTT sample (documentation) is used
plugin.PollingInterval = 500;

But inside the onPoll() we are using a
while (true) {...

What will happen here? Will be started the onPoll() again, even if it is running?
In this case here would be a
plugin.PollingInterval = -1;
better - for starting once only.

But if connection to broker is interrupted - the process will not start again…

Or is here any kind of “protection” that no duplicate processes can run?
Then this parameter could realize the reconnects…

(BTW a method “.isConnected” would be great :wink: …)

Thanks!

No. It will not be called while it’s already running. Think of PollingInterval as a delay. It is a delay between subsequent calls.

Great - so it could be used as “reconnect”.
(I know in this time there is any issue - so it does not help)

BTW: How will be detected the disconnect?

There is a isConnected property on the client

if(!_mqtt.isConnected)
{
    console.log("mqtt disconnected");
}
1 Like