opendata-stuttgart / sensors-software

sourcecode for reading sensor data
575 stars 313 forks source link

Added KEEP_ALIVE_TIME_MS period in favor of web interface; #967

Closed gvidinski closed 1 month ago

gvidinski commented 2 years ago

Hi guys, The newly added 'Power saving' option by @BasilFX is great. If activated, it has one drawback though which results in adding delay while web pages are served. Added 'keepAlive' check to fix that issue caused by 'delay (sleep)' at the end of 'loop ()' function. This way 'sleep' will be set to 0 milliseconds for the period of 'KEEP_ALIVE_TIME_MS' after 'last_page_load' time which is set to reasonable 30 seconds. This should be enough if one needs to browse around the web interface without being disturbed by annoying delay in page serve. Additionally, some refactoring was done, and early exit added (sleep > 0) for the 'delay(sleep)' call instead of calling 'delay(0)'.