-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retained messages not recieved upon subscribing #22
Comments
I'm going to need a log if you want me to look at this. |
Sorry for being hastily, should have been my first option. Cant see the problem though, other than MqttMessageType.subscribe The topic of my interest is
|
I noticed that if I specifically set void main() async {
initializeJsonMapper();
mqtt.client.logging(on: true);
var option = MqttSubscriptionOption();
option.retainHandling = MqttRetainHandling.doNotSendRetained;
var sub = MqttSubscription(MqttSubscriptionTopic("tinydb"), option);
print(sub.option!.retainHandling);
await mqtt.client.connect();
//mqtt.client.subscribe('tinydb', MqttQos.exactlyOnce);
mqtt.client.subscribeWithSubscription(sub);
//tinydbTopic.subscribe(MqttQos.exactlyOnce).listen((event) {
// print(event);
//});
runApp(const MyApp());
}
|
Yes there seems to be a bug with setting the option in the subscription, I'll look at this, however the default is to sendRetain so it should still work. What are you setting in your connection message? |
Hey, I use the default connection message (just the My initial setup just uses the Constructor with an client_id, then connect method and then I subscribe and listen to any messages in updates. When I subscribe the log prints a Just to be sure I wiped my pub-cache, but to no avail. |
Just had a hunch, I used your package with flutter build for Linux desktop. Tested it under Windows and no problem. Retained message received and everything seems to work as intended. I'm not sure if this could be even a bug with your library then, maybe something with how flutter builds for Linux. Also just noting that the The project I'm working on is supposed to run on android so I just should get used to using an emulator, or the real device. But in the case you would pursue this issue I'll leave it open. |
Fixed the subscription options bug, package re published at version 3.2.1 |
Hi, back at it again. So I was mistaken, it's not a OS based issue, after testing on both linux and windows I have a pretty reproducible bug. I decided to do a better job of showing you with a test file. Please have a look at my fork and see if you are able to reproduce same results on this test, and if it's making sense to you. There are two test cases, one does its job without waiting, that works. The other waits a little bit to simulate missing a published message. |
So are you still unable to receive retained messages on subscribtion? Because I'm unable to make it work as well for some reason and I wonder if we have the same problem. I'm testing it on Android tho. |
Yes, I have the same problem on android too. I don't know how to run the dart test straight on android, but the same behavior occurs in my flutter app. Mainly the reason I returned to this issue, because I plan to support the android version. |
Damn that makes my job a lot harder now 🥲. If I make it work I'll let you know. Thanks for the quick response! Edit: I've just tested the same setup on 3.1/3.1.1 mqtt_client (https://github.com/shamblett/mqtt_client) lib and it works as expected. So for you, if you don't need MQTT5 specifically I would recommend using the old client. |
I did that, and remained on v311 till now. But now I'm hoping to use version 5 features such as the response topics in Properties. It's not a big deal to put a response topic into the payload itself, but I'm hoping on this being resolved at some point for the rest of the features. |
I've played around with the Subscription options and found out that if you specify all the options like this:
it will eventually come but it takes like 20 seconds for some reason... |
Try your received_retained_message test code against Hives broker at broker.hivemq.com, I'm finding the tests reverse i.e. with waiting is OK now and without waiting fails, although I have changed your test code slightly. |
I can't get consistent results. It seems that one second is a low timeout for the broker. I set the broker sleep to 5 seconds and can confirm both tests working. I'll rewrite the test for a future so its faster if the broker responds sooner. Edit: |
For me, both the tests and my implementation as well are unreliable once it passes /retained message comes, once it doesn't. |
Same exact feeling. Did you check the new tests I made? There's 4 now and seem to be showing reproducible results now that I added a longer 5 second timeout. |
In theory shouldn't you wait until you have at least received the subscribe ack before you expect the retained message? Until you have received that you don't know if the subscription has been successful, from the Hive MQ docs -
So you should be able to connect a client, publish a retained message to a topic, disconnect the client, connect again and subscribe to the topic, when the subscribe ack is received you should then get the retained message. Bit more from the spec -
Are we sure the tests are actually doing this? |
Yes I did check the test and played with timeouts and delay but I wasn't able to get it to consistently pass all tests. |
I assumed the client handles ack on subscribe, I did wonder how it could do so synchronously. If not then I agree. This is surely something I've got to cover in the test. |
Hi, thank you for responding and trying to resolve this with us :)
Due to my use-case, I'm just listening for all messages coming to the topic at all times. But yes it I get subscribe ack message but the retained message is not coming on hivemq broker.
Yes I think I should be able to get the retained message after suback but on this client it simply wont come on hivemq broker or comes 30 sec after suback on empx broker. I expect it to behave more or less the same as on 3.1.1 is there something incorrect in this expectation? I've tried the setup on 3.1.1 by just switching the client to 3.1.1 and it worked flawlessly so I think something fishy is going on 😄 |
What broker are you using? I'm pretty much interested in only hosting my own on a raspberry pi, but using mosquitto has not worked at all for me (on version 5). |
I use mosquitto integration in my homeassistant instance (running on intel NUC) mainly for zigbee2mqtt but it proven to be very usefull as a test tool for my job as well. In the past I ran mosquitto on RPI and it worked just fine although you know, I wouldn't recommend opening it to the outside of the local network. |
@shamblett I've just noticed another weird thing. The time to receive any message seems to be inconsistent as well. It takes from less than a second to around 10 seconds even on my local broker. It wasn't like that in Mqtt 3.1.1 . Just wanted to share this as it might help you debug... |
Sorry for the spam but I think I've found a usable solution for now. This seems to work flawlessly as well for some reason it all works over WS. I still don't understand why this could happen ... This is also why it worked fine on my locally hosted broker when I tested it I've used WebSockets when I've realized this i tried using mqtt/tcp and it doesn't reliably work on my local broker . @sadilekivan I've edited your tests like this to support WebSockets could you try it if it works for you as well?
|
@Simonovsky Edit: Almost already forgot, nothing yet until the test confirms the sub ack. |
Thank you! Yes this means that all WebSockets worked. For me, it behaves differently each time I run it tcp connection seems to be super inconsitent. |
As far as I tried I cannot seem to get a message that was published before with a retain bit set.
Running dart client in Linux and Mosquitto broker with Rpi4. I tested my setup with a python paho client and I recieve retained messages fine. Anything I could be missing?
The text was updated successfully, but these errors were encountered: