-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
MQTT: Message Queue #975
Comments
@efuturetoday no, there is no way to remove published messages from the queue. You definitely have to use QoS=1 to rely on the callback as explained here #561 (comment). Your report seems to tell that you at least tried QoS=1 once? This should have done the job. Please post the full script, eg as a gist. |
AND THE runner.lua:
@devsaurus you are right first i had QoS set to 1 but then i experienced that the "runner" stopped working after some time and the callback with tmr.start(id) did not get fired. |
The callback should be fired reliably with QoS > 0. If that's not the case then we'd look at some kind of bug. This is what I like figure out. But your application is quite complex and contains concurrent scheduling of m:publish("/identify", cjson.encode(packet), 1, 0, function(conn)
RUNNERS.start()
print("[MQTT] identification sent!")
end)
m:subscribe(chipId.."/perform", 1, function() print("[MQTT] service listener registrated!") end)
-- don't start the RUNNERS immediately after m:publish()...
end) Handling the concurrency properly is not simple, I assume. So for further testing please strip down your code to comply with the rule above and make sure that two or more |
If I'm understanding your two statements together, if you publish with a qos=0, you may not ever be able to call publish again. The other issue you linked to mentioned a timeout, but you seem to be saying otherwise here... help? |
@markfinn the statements are related, yes.
Correct if you look at a typical solution. But we're already deep in FAQ topics here. It mentions the asynchronous nature of |
No, we're not. I understand asynchronous events. I'm trying to work out if your two statements are actually true because if they are then once you've sent a publish with a QOS=0 and it gets lost, you can never publish again, and I guess you would need to tear down the mqtt connection and restart. I hope your second statement about a timeout is possible because that would be much nicer than having to reconnect to the server, but it is in contradiction to your statement that:
|
I looked at the code on the mqtt module, and I notice that it doesn;t check the return code of espconn_sent() when it tries to send a packet. I suspect that part of the problem is that if two publish calls are made too close together, then the second one doesn't actually do the send and so the callback doesn't get called. It might be worth adding some logging to see if any of the network sending functions fail.... I also note that the code above doesn't check the return code from the publish calls either. I suspect that more error checking all round would be helpful. |
I can't speak for how NodeMCU code responds to the call back it's been a while since I have looked. What I can say is that when using QOS 0 the server never sends a PUBACK back to the client. So depending on how the NodeMCU code functions it may execute the callback immediately after send or it may just do nothing. http://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels |
i still think that adding a callback that is called whenever the |
Not sure what to make of this. Is it a bug in the firmware (i.e. the MQTT module) and if so where's the hard evidence? If there's no isolated test case then it probably falls under #719. That being said I remember two related SO questions I commented on: no publish callback after PUBACK http://stackoverflow.com/q/34382676/131929 and a tiny show case of how the queue works http://stackoverflow.com/a/33444636/131929 |
This might be related. I noticed back a while ago that the MQTT code under certian circumstances would upgrade a QOS 1 queued message to QOS 2. Then the queue would build up because the client never received the third part of the handshake and the server would drop the message. Thus the client would keep sending it. I couldn't track down what made it do this nor could I see in the code where it might be happening. The closest thing I could see in the logs was that it seemed to be related to getting a message with the ID of 2. The project I was using NodeMCU MQTT on has since passed (conference badge) so it left my radar. |
@efuturetoday #985 might be helpful there. It adds error checking to client functions and should enable better diagnostics (thanks for the heads-up @pjsg). |
This will make NodeMCU (commit c803756) reboot because of memory problems; heap decreases until NodeMCU resets.
|
Can you please check that each of the publish statements returns 'true'? I think that it is possible that there is a memory leak if they don't -- but it would be nice to know if that was the problem. |
OK -- it fails on my node as well. And there do not appear to be any obvious errors. Will investigate further. |
I'm closing this now with reference to #719 and summary:
@efuturetoday feel free to reopen this issue with an isolated testcase in case your problem wasn't fully addressed here. |
I do note that the bug is not yet fixed as the PR has not yet been merged..... |
I regard #975 (comment) as a separate topic, unrelated to the initial report where coding was discussed. Both got mixed up here and have different resolutions. |
Fix memory exhaustion in mqtt under circumstances from issue #975
Hello Dev-Team,
i really like your awesome framework and want to thank you first in place for your hard work!
I want to push sensor data to a mqtt broker in a certain period of time over and over.
Therefore i created a semi automated timer and start the timer again after i pushed the message with
I noticed that the timer would stop working after some time - because the callback get only called when PUBACK is received. With QoS 1 the same issue.
If i start the timer over and over like this:
After some time i will face a heap - overflow, because the message is added to the message queue.
Is there a way to remove the previous message from the mqtt-queue maybe with an id returned by
mqtt.client:publish
or a implement a callback that is fired when the message is removed from the message queue?Greetings!
The text was updated successfully, but these errors were encountered: