diff --git a/src/communication.jl b/src/communication.jl index fc1027f..3965dcd 100644 --- a/src/communication.jl +++ b/src/communication.jl @@ -156,6 +156,7 @@ function mqttClientInstance_v2( keepaliveCheckInterval::Integer=30, qos::MQTTClient.QOS=QOS_1, multiMsg::String="single", + clearOldMsg::Bool=true, ) client, connection = MQTTClient.MakeConnection(mqttBrokerAddress, mqttBrokerPort) @@ -182,6 +183,15 @@ function mqttClientInstance_v2( nothing, # store latest message to prevent doing the same massage twice ) + if clearOldMsg + chnames = keys(msgReceiveChannel) + for i in chnames + while isready(msgReceiveChannel[i]) + _ = take!(msgReceiveChannel[i]) + end + end + end + return instance end