diff --git a/HTML/Scaling.html b/HTML/Scaling.html
new file mode 100644
index 0000000..1fb1a13
--- /dev/null
+++ b/HTML/Scaling.html
@@ -0,0 +1,152 @@
+
+
+
+
\ No newline at end of file
diff --git a/config.txt b/config.txt
index efd59ab..d3bd190 100644
--- a/config.txt
+++ b/config.txt
@@ -3,7 +3,7 @@
"driverFileName":"flow-monitor.py",
"deviceName":"flowmonitor",
"driverId":"0140",
-"releaseVersion":"5",
+"releaseVersion":"6",
"files": {
"file1":"flow-monitor.py"}
diff --git a/flow-monitor.py b/flow-monitor.py
index 9fd68aa..8607f36 100644
--- a/flow-monitor.py
+++ b/flow-monitor.py
@@ -24,6 +24,29 @@ CLEAR_FLOWDATA = """UPDATE flow_data SET
bbl_totalizer_value=0.0,
last_measured_timestamp=0 WHERE id=1;"""
+CREATE_SCALINGDATA_TABLE = """CREATE TABLE scaling_data (
+ id integer PRIMARY KEY,
+ raw_min float,
+ raw_max float,
+ gpm_min float,
+ gpm_max float
+ );"""
+
+INSERT_SCALINGDATA = """INSERT INTO scaling_data (
+ id,
+ raw_min,
+ raw_max,
+ gpm_min,
+ gpm_max) VALUES (1, ?, ?, ?, ?);"""
+
+UPDATE_SCALINGDATA = """UPDATE scaling_data SET
+ raw_min=?,
+ raw_max=?,
+ gpm_min=?,
+ gpm_max=? WHERE id=1;"""
+
+
+
class Channel(object):
"""Meshify channel structure."""
@@ -79,9 +102,14 @@ class start(threading.Thread, deviceBase):
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q,
mcu=mcu, companyId=companyId, offset=offset,
mqtt=mqtt, Nodes=Nodes)
+ # Default Scaling Values for Flowmeter
+ self.RAW_MIN = 3.89
+ self.RAW_MAX = 19.54
+ self.GPM_MIN = 0.0
+ self.GPM_MAX = 100.0
self.daemon = True
- self.version = "5"
+ self.version = "6"
self.finished = threading.Event()
threading.Thread.start(self)
@@ -100,11 +128,6 @@ class start(threading.Thread, deviceBase):
startup_wait_seconds = 30
- raw_min = 3.89
- raw_max = 19.54
-
- gpm_min = 0.0
- gpm_max = 100.0
gpm_val = 0.0
gal_per_bbl = 42.0
@@ -113,7 +136,7 @@ class start(threading.Thread, deviceBase):
bbltotal_ch = Channel('bbl_total', galtotal_ch.senddelta_value/gal_per_bbl, total_time_store_delta)
gpmflow_ch = Channel('gpm_flow', 10.0, flow_time_store_delta)
- bpdflow_ch = Channel('bpd_flow', 5.0, flow_time_store_delta)
+ bpdflow_ch = Channel('bpd_flow', gpmflow_ch.senddelta_value * 34.2857, flow_time_store_delta)
runstatus_ch = Channel('run_status', 0.5, 600)
@@ -137,6 +160,27 @@ class start(threading.Thread, deviceBase):
cursor.execute(INSERT_BLANK_FLOWDATA)
conn.commit()
+ try:
+ cursor.execute('SELECT * FROM scaling_data WHERE id = 1')
+ stored_data = cursor.fetchone()
+ self.RAW_MIN = stored_data[1]
+ self.RAW_MAX = stored_data[2]
+ self.GPM_MIN = stored_data[3]
+ self.GPM_MAX = stored_data[4]
+ self.sendtodb("setrawmin", self.RAW_MIN, 0)
+ self.sendtodb("setrawmax", self.RAW_MAX, 0)
+ self.sendtodb("setgpmmin", self.GPM_MIN, 0)
+ self.sendtodb("setgpmmax", self.GPM_MAX, 0)
+ except (sqlite3.OperationalError, TypeError):
+ print("No table scaling_data in the database. I'll create it now.")
+ cursor.execute(CREATE_SCALINGDATA_TABLE)
+ cursor.execute(INSERT_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ self.sendtodb("setrawmin", self.RAW_MIN, 0)
+ self.sendtodb("setrawmax", self.RAW_MAX, 0)
+ self.sendtodb("setgpmmin", self.GPM_MIN, 0)
+ self.sendtodb("setgpmmax", self.GPM_MAX, 0)
+ conn.commit()
+
if not is_today(last_measured_timestamp):
gal_totalizer_value = 0.0
bbl_totalizer_value = 0.0
@@ -156,7 +200,7 @@ class start(threading.Thread, deviceBase):
din1_val = 1 if mcu_status['din1'] == 'On' else 0
if din1_val == 1:
- gpm_val = scale(cloop_val, raw_min, raw_max, gpm_min, gpm_max)
+ gpm_val = scale(cloop_val, self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX)
if gpm_val < 0:
gpm_val = 0
else:
@@ -206,7 +250,7 @@ class start(threading.Thread, deviceBase):
gal_totalizer_value = 0.0
bbl_totalizer_value = 0.0
cursor.execute('UPDATE flow_data SET gal_totalizer_value=?, bbl_totalizer_value=?, last_measured_timestamp=?',
- (gal_totalizer_value, bbl_totalizer_value, last_measured_timestamp))
+ (gal_totalizer_value, bbl_totalizer_value, last_measured_timestamp))
conn.commit()
date_reset = True
@@ -230,3 +274,63 @@ class start(threading.Thread, deviceBase):
cursor.execute(INSERT_BLANK_FLOWDATA)
conn.commit()
return(True)
+
+ def flowmonitor_setrawmin(self, name, value):
+ conn = sqlite3.connect('/root/python_firmware/drivers/flow-monitor.db')
+ cursor = conn.cursor()
+ try:
+ self.RAW_MIN = float(value)
+ cursor.execute(UPDATE_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ self.sendtodb("setrawmin", self.RAW_MIN, 0)
+ conn.commit()
+ except sqlite3.OperationalError:
+ print("No table flow_data in the database. I'll create it now.")
+ cursor.execute(CREATE_SCALINGDATA_TABLE)
+ cursor.execute(INSERT_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ conn.commit()
+ return(True)
+
+ def flowmonitor_setrawmax(self, name, value):
+ conn = sqlite3.connect('/root/python_firmware/drivers/flow-monitor.db')
+ cursor = conn.cursor()
+ try:
+ self.RAW_MAX = float(value)
+ self.sendtodb("setrawmax", self.RAW_MAX, 0)
+ cursor.execute(UPDATE_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ conn.commit()
+ except sqlite3.OperationalError:
+ print("No table flow_data in the database. I'll create it now.")
+ cursor.execute(CREATE_SCALINGDATA_TABLE)
+ cursor.execute(INSERT_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ conn.commit()
+ return(True)
+
+ def flowmonitor_setgpmmin(self, name, value):
+ conn = sqlite3.connect('/root/python_firmware/drivers/flow-monitor.db')
+ cursor = conn.cursor()
+ try:
+ self.GPM_MIN = float(value)
+ self.sendtodb("setgpmmin", self.GPM_MIN, 0)
+ cursor.execute(UPDATE_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ conn.commit()
+ except sqlite3.OperationalError:
+ print("No table flow_data in the database. I'll create it now.")
+ cursor.execute(CREATE_SCALINGDATA_TABLE)
+ cursor.execute(INSERT_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ conn.commit()
+ return(True)
+
+ def flowmonitor_setgpmmax(self, name, value):
+ conn = sqlite3.connect('/root/python_firmware/drivers/flow-monitor.db')
+ cursor = conn.cursor()
+ try:
+ self.GPM_MAX = float(value)
+ self.sendtodb("setgpmmax", self.GPM_MAX, 0)
+ cursor.execute(UPDATE_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ conn.commit()
+ except sqlite3.OperationalError:
+ print("No table flow_data in the database. I'll create it now.")
+ cursor.execute(CREATE_SCALINGDATA_TABLE)
+ cursor.execute(INSERT_SCALINGDATA, (self.RAW_MIN, self.RAW_MAX, self.GPM_MIN, self.GPM_MAX))
+ conn.commit()
+ return(True)
\ No newline at end of file