Completes FLOWMON-1. Increments to V6
This commit is contained in:
152
HTML/Scaling.html
Normal file
152
HTML/Scaling.html
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<div class="row row-flex">
|
||||||
|
<div class="col-md-6 box-me entry-top-level" id="setrawmin">
|
||||||
|
<div style="margin-left:15px;">
|
||||||
|
<h2>Raw Min</h2>
|
||||||
|
<form class="form-inline">
|
||||||
|
<div class="form-group" style="margin-bottom:15px;">
|
||||||
|
<label
|
||||||
|
class="sr-only"
|
||||||
|
for="<%= channels["flowmonitor.setrawmin"].channelId %>">Raw Min Value</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
class="form-control channel_value"
|
||||||
|
type="number"
|
||||||
|
step="any"
|
||||||
|
value="<%=channels['flowmonitor.setrawmin'].value %>">
|
||||||
|
<div class="input-group-addon">mA</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<a
|
||||||
|
href="#"
|
||||||
|
data-confirm-message="Are you sure you want to do this?"
|
||||||
|
data-refreshpause="1"
|
||||||
|
data-command=""
|
||||||
|
data-staticsend=1.0
|
||||||
|
data-channelId="<%= channels["flowmonitor.setrawmin"].channelId %>"
|
||||||
|
data-techname="<%=channels["flowmonitor.setrawmin"].techName %>"
|
||||||
|
data-name="<%= channels["flowmonitor.setrawmin"].name%>"
|
||||||
|
data-nodechannelcurrentId="<%= channels["flowmonitor.setrawmin"].nodechannelcurrentId %>"
|
||||||
|
id="<%= channels["flowmonitor.setrawmin"].channelId %>"
|
||||||
|
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6 box-me entry-top-level" id="setrawmax">
|
||||||
|
<div style="margin-left:15px;">
|
||||||
|
<h2>Raw Max</h2>
|
||||||
|
<form class="form-inline">
|
||||||
|
<div class="form-group" style="margin-bottom:15px;">
|
||||||
|
<label
|
||||||
|
class="sr-only"
|
||||||
|
for="<%= channels["flowmonitor.setrawmax"].channelId %>">Raw Max Value</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
class="form-control channel_value"
|
||||||
|
type="number"
|
||||||
|
step="any"
|
||||||
|
value="<%=channels['flowmonitor.setrawmax'].value %>">
|
||||||
|
<div class="input-group-addon">mA</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<a
|
||||||
|
href="#"
|
||||||
|
data-confirm-message="Are you sure you want to do this?"
|
||||||
|
data-refreshpause="1"
|
||||||
|
data-command=""
|
||||||
|
data-staticsend=1.0
|
||||||
|
data-channelId="<%= channels["flowmonitor.setrawmax"].channelId %>"
|
||||||
|
data-techname="<%=channels["flowmonitor.setrawmax"].techName %>"
|
||||||
|
data-name="<%= channels["flowmonitor.setrawmax"].name%>"
|
||||||
|
data-nodechannelcurrentId="<%= channels["flowmonitor.setrawmax"].nodechannelcurrentId %>"
|
||||||
|
id="<%= channels["flowmonitor.setrawmax"].channelId %>"
|
||||||
|
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6 box-me entry-top-level" id="setgpmmin">
|
||||||
|
<div style="margin-left:15px;">
|
||||||
|
<h2>GPM Min</h2>
|
||||||
|
<form class="form-inline">
|
||||||
|
<div class="form-group" style="margin-bottom:15px;">
|
||||||
|
<label
|
||||||
|
class="sr-only"
|
||||||
|
for="<%= channels["flowmonitor.setgpmmin"].channelId %>">GPM Min Value</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
class="form-control channel_value"
|
||||||
|
type="number"
|
||||||
|
step="any"
|
||||||
|
value="<%=channels['flowmonitor.setgpmmin'].value %>">
|
||||||
|
<div class="input-group-addon">GPM</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<a
|
||||||
|
href="#"
|
||||||
|
data-confirm-message="Are you sure you want to do this?"
|
||||||
|
data-refreshpause="1"
|
||||||
|
data-command=""
|
||||||
|
data-staticsend=1.0
|
||||||
|
data-channelId="<%= channels["flowmonitor.setgpmmin"].channelId %>"
|
||||||
|
data-techname="<%=channels["flowmonitor.setgpmmin"].techName %>"
|
||||||
|
data-name="<%= channels["flowmonitor.setgpmmin"].name%>"
|
||||||
|
data-nodechannelcurrentId="<%= channels["flowmonitor.setgpmmin"].nodechannelcurrentId %>"
|
||||||
|
id="<%= channels["flowmonitor.setgpmmin"].channelId %>"
|
||||||
|
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6 box-me entry-top-level" id="setgpmmax">
|
||||||
|
<div style="margin-left:15px;">
|
||||||
|
<h2>GPM Max</h2>
|
||||||
|
<form class="form-inline">
|
||||||
|
<div class="form-group" style="margin-bottom:15px;">
|
||||||
|
<label
|
||||||
|
class="sr-only"
|
||||||
|
for="<%= channels["flowmonitor.setgpmmax"].channelId %>">GPM Max Value</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
class="form-control channel_value"
|
||||||
|
type="number"
|
||||||
|
step="any"
|
||||||
|
value="<%=channels['flowmonitor.setgpmmax'].value %>">
|
||||||
|
<div class="input-group-addon">GPM</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<a
|
||||||
|
href="#"
|
||||||
|
data-confirm-message="Are you sure you want to do this?"
|
||||||
|
data-refreshpause="1"
|
||||||
|
data-command=""
|
||||||
|
data-staticsend=1.0
|
||||||
|
data-channelId="<%= channels["flowmonitor.setgpmmax"].channelId %>"
|
||||||
|
data-techname="<%=channels["flowmonitor.setgpmmax"].techName %>"
|
||||||
|
data-name="<%= channels["flowmonitor.setgpmmax"].name%>"
|
||||||
|
data-nodechannelcurrentId="<%= channels["flowmonitor.setgpmmax"].nodechannelcurrentId %>"
|
||||||
|
id="<%= channels["flowmonitor.setgpmmax"].channelId %>"
|
||||||
|
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$('.channel_value').each(function(topLevel){
|
||||||
|
$(this).change(function(){
|
||||||
|
var id = "#" + $(this).closest(".entry-top-level").attr('id');
|
||||||
|
if (id !== "#undefined"){
|
||||||
|
var val = $(id).find('.channel_value').val();
|
||||||
|
var tag = $(id).find('.setstatic').attr('data-staticsend', val);
|
||||||
|
console.log($(id).find('.setstatic').attr('data-staticsend'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
"driverFileName":"flow-monitor.py",
|
"driverFileName":"flow-monitor.py",
|
||||||
"deviceName":"flowmonitor",
|
"deviceName":"flowmonitor",
|
||||||
"driverId":"0140",
|
"driverId":"0140",
|
||||||
"releaseVersion":"5",
|
"releaseVersion":"6",
|
||||||
"files": {
|
"files": {
|
||||||
"file1":"flow-monitor.py"}
|
"file1":"flow-monitor.py"}
|
||||||
|
|
||||||
|
|||||||
122
flow-monitor.py
122
flow-monitor.py
@@ -24,6 +24,29 @@ CLEAR_FLOWDATA = """UPDATE flow_data SET
|
|||||||
bbl_totalizer_value=0.0,
|
bbl_totalizer_value=0.0,
|
||||||
last_measured_timestamp=0 WHERE id=1;"""
|
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):
|
class Channel(object):
|
||||||
"""Meshify channel structure."""
|
"""Meshify channel structure."""
|
||||||
|
|
||||||
@@ -79,9 +102,14 @@ class start(threading.Thread, deviceBase):
|
|||||||
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q,
|
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q,
|
||||||
mcu=mcu, companyId=companyId, offset=offset,
|
mcu=mcu, companyId=companyId, offset=offset,
|
||||||
mqtt=mqtt, Nodes=Nodes)
|
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.daemon = True
|
||||||
self.version = "5"
|
self.version = "6"
|
||||||
self.finished = threading.Event()
|
self.finished = threading.Event()
|
||||||
threading.Thread.start(self)
|
threading.Thread.start(self)
|
||||||
|
|
||||||
@@ -100,11 +128,6 @@ class start(threading.Thread, deviceBase):
|
|||||||
|
|
||||||
startup_wait_seconds = 30
|
startup_wait_seconds = 30
|
||||||
|
|
||||||
raw_min = 3.89
|
|
||||||
raw_max = 19.54
|
|
||||||
|
|
||||||
gpm_min = 0.0
|
|
||||||
gpm_max = 100.0
|
|
||||||
gpm_val = 0.0
|
gpm_val = 0.0
|
||||||
|
|
||||||
gal_per_bbl = 42.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)
|
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)
|
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)
|
runstatus_ch = Channel('run_status', 0.5, 600)
|
||||||
|
|
||||||
@@ -137,6 +160,27 @@ class start(threading.Thread, deviceBase):
|
|||||||
cursor.execute(INSERT_BLANK_FLOWDATA)
|
cursor.execute(INSERT_BLANK_FLOWDATA)
|
||||||
conn.commit()
|
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):
|
if not is_today(last_measured_timestamp):
|
||||||
gal_totalizer_value = 0.0
|
gal_totalizer_value = 0.0
|
||||||
bbl_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
|
din1_val = 1 if mcu_status['din1'] == 'On' else 0
|
||||||
if din1_val == 1:
|
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:
|
if gpm_val < 0:
|
||||||
gpm_val = 0
|
gpm_val = 0
|
||||||
else:
|
else:
|
||||||
@@ -206,7 +250,7 @@ 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
|
||||||
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=?',
|
||||||
(gal_totalizer_value, bbl_totalizer_value, last_measured_timestamp))
|
(gal_totalizer_value, bbl_totalizer_value, last_measured_timestamp))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
date_reset = True
|
date_reset = True
|
||||||
|
|
||||||
@@ -230,3 +274,63 @@ class start(threading.Thread, deviceBase):
|
|||||||
cursor.execute(INSERT_BLANK_FLOWDATA)
|
cursor.execute(INSERT_BLANK_FLOWDATA)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return(True)
|
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)
|
||||||
Reference in New Issue
Block a user