Hello!
Faced a problem. It seems to have been solved, but I would like to understand its reason.
It doesn’t work like that, only the first message is executed.
val mqttActions = getActions(“mqtt”, “mqtt:broker:MyBroker”)
mqttActions.publishMQTT(“ESP32_Barn/gpio/2”, “1”)
val mqttActions = getActions(“mqtt”, “mqtt:broker:MyBroker”)
mqttActions.publishMQTT(“ESP32_Barn/gpio/5”, “1”)
And this is how both are performed.
val mqttActions = getActions(“mqtt”, “mqtt:broker:MyBroker”)
mqttActions.publishMQTT(“ESP32_Barn/gpio/2”, “1”)
t0 = createTimer(now.plusSeconds(1), [ |
val mqttActions = getActions(“mqtt”, “mqtt:broker:MyBroker”)
mqttActions.publishMQTT(“ESP32_Barn/gpio/5”, “1”)
])
In this case, the presence of the delay does not affect anything. But I’m afraid, suddenly, at some unpredictable moment, several messages will come in a row. Until I knew about this phenomenon, I never worried.
for the first example, it shouldn’t be necessary to redefine mqttActions, in fact, I would expect an exception, as you do a double definition of a val.
val mqttActions = getActions("mqtt", "mqtt:broker:MyBroker")
mqttActions.publishMQTT("ESP32_Barn/gpio/2", "1")
mqttActions.publishMQTT("ESP32_Barn/gpio/5", "1")