tess1o / go-ecoflow-exporter

MIT License
24 stars 2 forks source link

Add mqtt reconnect on idle #10

Closed pontostroy closed 1 month ago

pontostroy commented 1 month ago

Please add this feature as in python exporter, reconnect if empty queue after using mobile app.

tess1o commented 1 month ago

I will check the issue in this exporter and if MQTT behaves in the same way I'll implement the reconnection after not recieiving messages for XXX seconds.

tess1o commented 1 month ago

Yes, the issue can be reproduced on IOS and MQTT exporter (exporter via REST API works fine).

I'll prepare a fix. There are two options:

  1. Unsubscribe from the topic (where we receive messages from the devices) and then subscribe again. I need to test if it helps.
  2. Disconnect from the broker and connect again.

I'd prefer the first option if it works.

tess1o commented 1 month ago

Implemented in version 1.2.1 - https://github.com/tess1o/go-ecoflow-exporter/releases/tag/1.2.1

The logic is the following: Check if we don't receive messages from MQTT for all devices within threshold (env variable MQTT_DEVICE_OFFLINE_THRESHOLD_SECONDS, default value 60 seconds). If true, disconnect from broker and connect again.

Note: If one device receives messages and another device doesn't receive messages, it means that the second device is just offline and there is no need to reconnect. In this case we set all metrics to 0.

Thank you for pointing to this critical issue.