Why is there a need to pause between posting MQTT messages?

  • OS: Windows 7
  • Java Runtime Environment: Zulu 11
  • openHAB version: 3
  • Eclipse Mosquitto

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”)
])

Why is that?

We couldn’t say how your device performs when receiving messages in quick succession.

We couldn’t say if your broker settings might allow close together messages to arrive out of order. Would that matter here?

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")

should suffice.

2 Likes

Thank you! It Works. It’s my own fault, you can’t use CTRL-C and CTRL-V without thinking.