diff --git a/app.py b/app.py index 1b256b0..b42a818 100644 --- a/app.py +++ b/app.py @@ -14,7 +14,11 @@ except ImportError: app = Flask(__name__) SOCKET_TIMEOUT = getattr(config, "INVERTER_SOCKET_TIMEOUT", 5) -CACHE_TTL = 2.0 # seconds; the logger only tolerates one session at a time +# The dashboard polls every CLIENT_POLL_INTERVAL seconds. Cache a reading for slightly +# less than that, so one client's poll refreshes the data and any other clients polling +# within the window get the cached reply (the logger only tolerates one session at a time). +CLIENT_POLL_INTERVAL = 5.0 +CACHE_TTL = CLIENT_POLL_INTERVAL - 0.2 _lock = threading.Lock() _cache = {"time": 0.0, "data": None} @@ -243,7 +247,7 @@ def write_inverter_registers(writes): @app.route('/') def index(): - return render_template('index.html', writable=WRITABLE) + return render_template('index.html', writable=WRITABLE, poll_interval_ms=int(CLIENT_POLL_INTERVAL * 1000)) @app.route('/api/data') def api_data(): diff --git a/templates/index.html b/templates/index.html index b50cdda..ef11e38 100644 --- a/templates/index.html +++ b/templates/index.html @@ -663,9 +663,9 @@ } } - // Fetch immediately, then every 5 seconds + // Fetch immediately, then at the server-defined interval (CLIENT_POLL_INTERVAL in app.py) fetchData(); - setInterval(fetchData, 5000); + setInterval(fetchData, {{ poll_interval_ms }});