-
Notifications
You must be signed in to change notification settings - Fork 95
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
🚨 Telegram order not preserved in MQTT message order #1714
Comments
You may want to enable DEBUG level logging in DSMR-reader and check the dsmr_backend process log for a verbose dump of the Paho MQTT client. DSMR-reader does not have a dedicated proces for handling MQTT.
Data sources queue messages in DSMR-reader and every backend run it will spend time processing the queue. These should, however, preserve their order.
The debug logging will show you what happens when in DSMR-reader, how fast the broker reacts etc. It's a good starting point for further investigation.
|
For sample debug logging format I mean, see this dump for example: #1383 (comment)
|
I've had a quick look at the debug logs and I think I'm seeing behaviour that could explain this. It looks like the MQTT message queue is being emptied in a descending order. I've still got to debug it further to be certain, though. But seeing the logs, it wouldn't surprise me that new messages get added to the front of the queue and therefore get sent first. I'm going to adjust my input and output monitoring to add more information so I can monitor the whole data flow, but I'm not sure whether I'll have time for that today.
|
I found some time to dive into the code and am suspicious of this line: https://github.com/dsmrreader/dsmr-reader/blob/v5/dsmr_mqtt/services/broker.py#L74 |
Thanks! I think it was a side effect of refactoring the ORM lookup for queue limits, as this is a shortcut for fetching the last X messages. But this is not how it was intended to work, as it also affects the actual sorting of the messages fetched from the queue. Too bad it's been in there for four years it seems, but maybe this only happens whenever the data throughput is high, hence why only some people notice it.
I'll have a deeper look tonight and will have the queryset resorted after whatever it's doing now due to queue limits. Also, adding a test to verify the sorting outcome will prevent this from happening again.
As I still have a smart meter emitting a telegram once every 10s and I'm not using MQTT myself, or I may have noticed it a bit sooner myself.
|
It's also not really something most people will notice, as the difference is minimal and, indeed, only happens when a lot of messages are being sent. As I see you're reacting via e-mail, I think you didn't see the edit yet in my previous message: I suspect it might be more efficient to sort in an ascending way with |
It seems I can't use negative indexing nor reordering it later in the query after slicing, which must be the reason I wrote it initially this way. |
I made a fix that'll probably be released Saturday in v5.8 |
Released in v5.8 |
I've had my monitoring script run for the whole day and didn't encounter a single issue any more. That fully confirms that this issue is now fixed 👍 Thanks for the quick turnaround on this one! |
Great, thanks for checking! |
Description
I've been running into warning messages in Home Assistant indicating that certain MQTT topics aren't strictly increasing all the time, as have several other people for at least a year. I'm not talking about the daily resets in some topics, but about an issue that pops up once every few minutes. It mostly seems to happen with
dsmr/day-consumption/electricity1
anddsmr/day-consumption/electricity2
for me, but I've seen it in other topics as well. This is an issue, because you don't really expect these values to ever go down (excluding the daily resets). It was initially expecting the meter to do bad readings. But after some investigation, it seems like something else is going on within DSMR Reader.Here's my setup: Raspberry Pi with the remote datalogger script connected to a Belgian Fluvius smart energy meter -> Docker instance of DSMR Reader -> local MQTT Broker -> Home Assistant
I slightly modified the remote datalogger script to also send a POST request to an endpoint I wrote to parse the telegram and check whether the new value is lower than the previous value. I also wrote a small application that subscribes to the DSMR MQTT topics, that does the same check. The application reading the MQTT messages is indicating a decrease every couple of minutes, while the endpoint that receives the telegrams so far hasn't registered any decreases. Just to be safe, I've verified that it really is working by temporarily logging every increase in value.
So it would seem that, for some reason, the MQTT messages aren't being sent in the same order as the telegrams are being received. I didn't fully dive into the DSMR Reader codebase myself to search for a cause yet.
Note: feel free to respond in Dutch, I'm just used to writing all my issues in English, and it's a hard habit to shake off.
DSMR-reader version
5.7.0
DSMR-reader platform
Docker (e.g. Xirixiz)
Debug info dump
No response
The text was updated successfully, but these errors were encountered: