From 2970ac9f5a74c709d04542c01b92bd9ec1643bf0 Mon Sep 17 00:00:00 2001 From: Nico Melone Date: Thu, 30 Jan 2020 17:01:36 -0600 Subject: [PATCH] updated run_status determination --- flow-monitor/config.txt | 2 +- flow-monitor/flow-monitor.py | 43 +++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/flow-monitor/config.txt b/flow-monitor/config.txt index 75c0338..2d3211e 100644 --- a/flow-monitor/config.txt +++ b/flow-monitor/config.txt @@ -6,6 +6,6 @@ }, "deviceName": "flowmonitor", "driverId": "0140", - "releaseVersion": "17", + "releaseVersion": "18", "driverFileName": "flow-monitor.py" } \ No newline at end of file diff --git a/flow-monitor/flow-monitor.py b/flow-monitor/flow-monitor.py index e2f3e15..0f584c7 100644 --- a/flow-monitor/flow-monitor.py +++ b/flow-monitor/flow-monitor.py @@ -176,10 +176,11 @@ class start(threading.Thread, deviceBase): self.GPM_IGNORE_LIMIT = 1.0 self.gpm_or_bpd = "gpm" + self.lowflow = 10.00 self.force_send = False self.daemon = True - self.version = "17" + self.version = "18" self.finished = threading.Event() threading.Thread.start(self) @@ -270,6 +271,14 @@ class start(threading.Thread, deviceBase): persistence.store(PERSIST) self.sendtodb("gpmorbpd", self.gpm_or_bpd, 0) + try: + self.lowflow = PERSIST["lowflow"] + except KeyError: + logger.warning("No low flow value in configuratin file. Will add one now") + PERSIST["lowflow"] = self.lowflow + persistence.store(PERSIST) + self.sendtodb("setlowflow", self.lowflow,0) + try: self.flow_raw_min = PERSIST["flow_raw_min"] self.flow_raw_max = PERSIST["flow_raw_max"] @@ -347,8 +356,6 @@ class start(threading.Thread, deviceBase): din1_val = 1 if mcu_status['din1'] == 'On' else 0 # Check DIGITAL INPUT 1 for run status scaled_cloop = scale(cloop_val, self.flow_raw_min, self.flow_raw_max, self.flow_gpm_min, self.flow_gpm_max) psi_val = scale(analog1_val, self.pressure_raw_min, self.pressure_raw_max, self.pressure_psi_min, self.pressure_psi_max) - if din1_val == 0 and scaled_cloop > 10: - din1_val = 1 if self.gpm_or_bpd == "gpm": @@ -361,6 +368,20 @@ class start(threading.Thread, deviceBase): if gpm_val < self.GPM_IGNORE_LIMIT: gpm_val = 0 bpd_val = 0 + + #Determine run status + runstatus = 0 + if din1_val == 0 and gpm_val == 0: + runstatus = 0 #Stopped + elif din1_val == 0 and gpm_val > 10: + runstatus = 1 #Assumed running might not have run indication + elif din1_val == 1 and gpm_val == 0: + runstatus = 3 #no flow warning + elif din1_val == 1 and gpm_val < self.lowflow: + runstatus = 4 #low flow warning + elif din1_val == 1 and gpm_val >= self.lowflow: + runstatus = 1 #running normally + now = time.time() time_diff = now - last_measured_timestamp if time_diff > 0 and time_diff < 180: @@ -431,9 +452,9 @@ class start(threading.Thread, deviceBase): self.sendtodb(psipressure_ch.meshify_name, psi_val, 0) psipressure_ch.update(psi_val, now) - if runstatus_ch.check_if_send_needed(din1_val, now) or self.force_send: - self.sendtodb(runstatus_ch.meshify_name, din1_val, 0) - runstatus_ch.update(din1_val, now) + if runstatus_ch.check_if_send_needed(runstatus, now) or self.force_send: + self.sendtodb(runstatus_ch.meshify_name, runstatus, 0) + runstatus_ch.update(runstatus, now) # Check for the clock hitting midnight for resetting the daily totalizer value @@ -629,3 +650,13 @@ class start(threading.Thread, deviceBase): except Exception as e: logger.error("Error during flowmonitor_setgpmorbpd: {}".format(e)) return False + + def flowmonitor_setlowflow(self, name, value): + """Set the low flow limit""" + try: + self.lowflow = value + self.sendtodb("setlowflow", self.lowflow,0) + return True + except Exception as e: + logger.error("Error during flomonitor_setlowflow: {}".format(e)) + return False