Fix for FLOWMON-3
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"driverFileName":"flow-monitor.py",
|
"driverFileName":"flow-monitor.py",
|
||||||
"deviceName":"flowmonitor",
|
"deviceName":"flowmonitor",
|
||||||
"driverId":"0140",
|
"driverId":"0140",
|
||||||
"releaseVersion":"4",
|
"releaseVersion":"5",
|
||||||
"files": {
|
"files": {
|
||||||
"file1":"flow-monitor.py"}
|
"file1":"flow-monitor.py"}
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ class Channel(object):
|
|||||||
|
|
||||||
def scale(raw_val, raw_min, raw_max, eu_min, eu_max):
|
def scale(raw_val, raw_min, raw_max, eu_min, eu_max):
|
||||||
"""Scale a raw value."""
|
"""Scale a raw value."""
|
||||||
m = (eu_max - eu_min) / (raw_max - raw_min)
|
slope = (eu_max - eu_min) / (raw_max - raw_min)
|
||||||
b = eu_max - (m * raw_max)
|
intercept = eu_max - (slope * raw_max)
|
||||||
return m * raw_val + b
|
return slope * raw_val + intercept
|
||||||
|
|
||||||
|
|
||||||
def is_today(tstamp):
|
def is_today(tstamp):
|
||||||
@@ -81,7 +81,7 @@ class start(threading.Thread, deviceBase):
|
|||||||
mqtt=mqtt, Nodes=Nodes)
|
mqtt=mqtt, Nodes=Nodes)
|
||||||
|
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.version = "4"
|
self.version = "5"
|
||||||
self.finished = threading.Event()
|
self.finished = threading.Event()
|
||||||
threading.Thread.start(self)
|
threading.Thread.start(self)
|
||||||
|
|
||||||
@@ -121,7 +121,6 @@ class start(threading.Thread, deviceBase):
|
|||||||
|
|
||||||
gal_totalizer_value = 0.0
|
gal_totalizer_value = 0.0
|
||||||
bbl_totalizer_value = 0.0
|
bbl_totalizer_value = 0.0
|
||||||
last_measured_timestamp = 0
|
|
||||||
|
|
||||||
last_measured_timestamp = time.time()
|
last_measured_timestamp = time.time()
|
||||||
conn = sqlite3.connect('/root/python_firmware/drivers/flow-monitor.db')
|
conn = sqlite3.connect('/root/python_firmware/drivers/flow-monitor.db')
|
||||||
@@ -167,11 +166,12 @@ class start(threading.Thread, deviceBase):
|
|||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
time_diff = now - last_measured_timestamp
|
time_diff = now - last_measured_timestamp
|
||||||
gal_flow_delta = (time_diff / 60.0) * gpm_val
|
if time_diff > 0:
|
||||||
bbl_flow_delta = (time_diff / 60.0) * (1.0 / 60.0) * (1.0 / 24.0) * bpd_val
|
gal_flow_delta = (time_diff / 60.0) * gpm_val
|
||||||
|
bbl_flow_delta = (time_diff / 60.0) * (1.0 / 60.0) * (1.0 / 24.0) * bpd_val
|
||||||
|
|
||||||
gal_totalizer_value += gal_flow_delta
|
gal_totalizer_value += gal_flow_delta
|
||||||
bbl_totalizer_value += bbl_flow_delta
|
bbl_totalizer_value += bbl_flow_delta
|
||||||
last_measured_timestamp = now
|
last_measured_timestamp = now
|
||||||
|
|
||||||
cursor.execute('UPDATE flow_data SET gal_totalizer_value=?, bbl_totalizer_value=?, last_measured_timestamp=?',
|
cursor.execute('UPDATE flow_data SET gal_totalizer_value=?, bbl_totalizer_value=?, last_measured_timestamp=?',
|
||||||
|
|||||||
Reference in New Issue
Block a user