randomsync / robotframework-mqttlibrary

MQTT Keyword Library for Robot Framework
Apache License 2.0
25 stars 30 forks source link

subscribe async not work due to time out - loop() in connect fails ? #15

Closed rfsch closed 4 years ago

rfsch commented 4 years ago

Hi

I am using subscribe with timeout=0 aka async subscribe But my MQTT client times out due to a 5 minutes delay of the server publishing to the topic subscribed. I tried every possible variation without success.

It seems that the loop() of the connect is not working keeping the client alive ?

How can I solve this problem ?

Thanks

Rodaxfck commented 4 years ago

I have also this kind of problem, sometimes it works great, and sometimes I got 0 message from the 'Listen' keyword

@{response}= MQTTLibrary.Subscribe ${MQTT_SUBSCRIBE_COMMANDS} 0 0 0 # async Start / End / Elapsed: 20200206 05:53:50.408 / 20200206 05:53:50.409 / 00:00:00.001 05:53:50.409 INFO Subscribing to topic: dev/cmd
05:53:50.409 INFO Starting background loop
05:53:50.409 INFO @{response} = [ ]

And 13 seconds after (I should have a message after some little steps)

@{response}= MQTTLibrary.Listen ${MQTT_SUBSCRIBE_COMMANDS} timeout=10 limit=1 Start / End / Elapsed: 20200206 05:54:03.929 / 20200206 05:54:03.930 / 00:00:00.001 05:54:03.930 WARN Cannot listen when not subscribed to a topic
05:54:03.930 INFO @{response} = [ ]

What is this warn ? I subscribed earlier

deneb78it commented 4 years ago

I have the same issue.

My code contain these lines:

${messages}     Subscribe          topic=${topic}  qos=0  limit=0   timeout=0
${messages}     Listen          topic=${topic}    limit=20   timeout=10s

and the execution ends immediately after the subscription with this warning:

[ WARN ] Cannot listen when not subscribed to a topic

It seems like the subscription is immediately left.

randomsync commented 4 years ago

@rfsch @Rodaxfck @deneb78it: can someone please provide a complete test which produces this issue so I can try locally? thanks.

Rodaxfck commented 4 years ago

It's really random @randomsync, I had this WARN today but it happens 1 time / 10 attemps. You can try with @deneb78it example, you should have the issue. :/

randomsync commented 4 years ago

@deneb78it @Rodaxfck I have a proposed fix in this branch #20. The test I added for this specific scenario passes now, could you please give it a try? That branch has fixes for both the wildcard issue and this issue.

randomsync commented 4 years ago

fixed in #20