bachya / ecowitt2mqtt

Send data from Fine Offset weather stations (Ecowitt, Ambient Weather, Froggit, etc.) to MQTT!
MIT License
210 stars 44 forks source link

feat: add ability to configure MQTT message and session expiry intervals #1037

Open bachya opened 2 months ago

bachya commented 2 months ago

Describe what the PR does:

Background: https://www.hivemq.com/blog/mqtt5-essentials-part4-session-and-message-expiry/

Does this fix a specific issue?

Fixes https://github.com/bachya/ecowitt2mqtt/issues/1024

Checklist:

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (7eae99f) to head (e6a4102). Report is 28 commits behind head on dev.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #1037 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 32 32 Lines 1775 1805 +30 ========================================= + Hits 1775 1805 +30 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jwillmer commented 1 month ago

Is this code available as a docker container? Then I could test it on my setup.

bachya commented 1 month ago

Is this code available as a docker container? Then I could test it on my setup.

https://github.com/bachya/ecowitt2mqtt/pkgs/container/ecowitt2mqtt/242520435?tag=pr-1037

jwillmer commented 1 month ago

it did not report me the message once i reconnected. but i need to check if all services are using the latest protocol. Would be good we get a second validation.

jwillmer commented 1 month ago

Today it crashed with this message. My broker supports MQTT5 and I did not modify my env variables since you use already good defaults.

2024-07-18 22:50:07,952 | ERROR | <class 'ValueError'> exception caused a shutdown: Properties only apply to MQTT V5
Traceback (most recent call last):
  File "/venv/lib/python3.11/site-packages/ecowitt2mqtt/runtime.py", line 114, in create_loop
    async with Client(
  File "/venv/lib/python3.11/site-packages/aiomqtt/client.py", line 707, in __aenter__
    await loop.run_in_executor(
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1431, in connect
    raise ValueError("Properties only apply to MQTT V5")
ValueError: Properties only apply to MQTT V5
bachya commented 1 month ago

Today it crashed with this message. My broker supports MQTT5 and I did not modify my env variables since you use already good defaults.


2024-07-18 22:50:07,952 | ERROR | <class 'ValueError'> exception caused a shutdown: Properties only apply to MQTT V5

Traceback (most recent call last):

  File "/venv/lib/python3.11/site-packages/ecowitt2mqtt/runtime.py", line 114, in create_loop

    async with Client(

  File "/venv/lib/python3.11/site-packages/aiomqtt/client.py", line 707, in __aenter__

    await loop.run_in_executor(

  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run

    result = self.fn(*self.args, **self.kwargs)

             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1431, in connect

    raise ValueError("Properties only apply to MQTT V5")

ValueError: Properties only apply to MQTT V5

Interesting. Perhaps I need to somehow specify the MQTT version when I create a client. I'll investigate.

bachya commented 1 month ago

Thanks for your patience, @jwillmer. I just pushed new code that allows you to change the version of the MQTT protocol inside ecowitt2mqtt's MQTT client. Once the build finishes, you can pull that same Docker image and try again. You'll use the ECOWITT2MQTT_MQTT_PROTOCOL_VERSION environment variable with a value of 5.

jwillmer commented 1 month ago

That is my output. Sadly something is still broken? I use eclipse-mosquitto:2 docker image and according to the ChatGPT it supports MQTT version 5 out of the box without any additional configuration.

2024-08-05 15:35:06,695 | INFO | Starting ecowitt2mqtt (version 2024.06.2)
2024-08-05 15:35:51,481 | ERROR | <class 'ValueError'> exception caused a shutdown: Properties only apply to MQTT V5
Traceback (most recent call last):
  File "/venv/lib/python3.11/site-packages/ecowitt2mqtt/runtime.py", line 116, in create_loop
    async with Client(
  File "/venv/lib/python3.11/site-packages/aiomqtt/client.py", line 707, in __aenter__
    await loop.run_in_executor(
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1431, in connect
    raise ValueError("Properties only apply to MQTT V5")
ValueError: Properties only apply to MQTT V5
bachya commented 1 month ago

Can I see your verbose-level output when you start ecowitt2mqtt? That message comes from the MQTT client, so I think there's something wrong here vs. with mosquitto.

github-actions[bot] commented 1 week ago

There hasn't been any activity on this pull request recently, so it has automatically been marked as stale and will be closed if no further action occurs within 7 days. Thank you for your contributions.