Sub ConnectAndReconnect
If mqtt.IsInitialized Then mqtt.Close
mqtt.Initialize("mqtt", serverURI, Rnd(0, 999999999) & DateTime.Now)
Dim mo As MqttConnectOptions
mo.Initialize("xxx", "xxx")
Log("Trying to connect")
mqtt.Connect2(mo)
Wait For mqtt_Connected (Success As Boolean)
If Success Then
Log("Mqtt connected")
mqttConnected=True
Else
mqttConnected=False
Log("Error connecting.")
End If
End Sub