Skip to content

Commit

Permalink
improved measurement period timing to exclude measurement time
Browse files Browse the repository at this point in the history
  • Loading branch information
kolinger committed Dec 15, 2021
1 parent 738a406 commit 953d5ef
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions webapp/backend.py
Expand Up @@ -12,7 +12,7 @@
import pendulum
from serial.tools.list_ports import comports
from socketio import Namespace

from timeit import default_timer as timer
from interfaces.tc import TcBleInterface
from interfaces.wrapper import Wrapper
from utils.config import Config
Expand Down Expand Up @@ -191,8 +191,11 @@ def run(self):
self.emit("connected")
self.log("Connected")

interval = float(self.config.read("rate"))
while self.running:
begin = timer()
data = self.retry(self.interface.read)

if isinstance(data, str):
if data in ["disconnected", "connected"]:
self.disconnect()
Expand All @@ -204,7 +207,11 @@ def run(self):
data["name"] = self.config.read("name")
self.update(data)
self.storage.store_measurement(data)
sleep(self.config.read("rate"))

measurement_runtime = timer() - begin
sleep_time = interval - measurement_runtime
if sleep_time > 0:
sleep(sleep_time)

except (KeyboardInterrupt, SystemExit):
raise
Expand Down

0 comments on commit 953d5ef

Please sign in to comment.