Merge pull request #1 from Henry-Pump/add-pressure-transmitter

Add pressure transmitter
This commit is contained in:
Patrick McDonagh
2018-05-15 16:03:56 -05:00
committed by GitHub
6 changed files with 277 additions and 20 deletions

View File

@@ -65,9 +65,44 @@
</div>
</div>
<% } %>
<% if (channels["pondlevel.pressure_psi"].value > 0.0){ %>
<div class="row row-flex box-me">
<div class='col-xs-4 text-center'>
<h2>Pressure</h2>
<div class="gauge-box">
<div data-labelheight="10"
style="height: 170px; background: transparent; margin: 0 auto;"
id="gauge-pressure_psi"
data-chart="solidgauge"
data-nodename="pondlevel.pressure_psi"
data-units="PSI"
data-min="0"
data-max="600"
data-decimalplaces="1"
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
data-valuefontsize="18px">
</div>
<div class- "timestamp-box">
<a href="#" data-channelId="<%= channels['pondlevel.pressure_psi'].channelId %>" class="data-table" title="Download Channel History">
<i class="fa fa-download"></i>
</a>
</div>
<span data-timeupdate="pond_level">
<%= channels["pondlevel.pressure_psi"].timestamp %>
</span>
</div>
</div>
<div class='col-xs-8'>
<div style="height:300px" id="chart-pressure_psi" data-chart="chart" data-nodename1="pondlevel.pressure_psi" data-datalabel1="Pressure" data-daysofhistory="2" data-chartlabel="Pond Volume" data-ylabel="" data-xlabel="Date" data-units=" PSI"></div>
</div>
</div>
<% } %>
<h1 class="pad15">Configuration</h1>
<div class="row row-flex">
<div class="col-md-6 box-me entry-top-level" id="low_level_limit">
<div class="col-md-4 box-me entry-top-level" id="low_level_limit">
<div class="pad15">
<h2>Low Level Limit</h2>
<form class="form-inline">
@@ -92,7 +127,7 @@
</div>
</div>
<div class="col-md-6 box-me entry-top-level" id="high_level_limit">
<div class="col-md-4 box-me entry-top-level" id="high_level_limit">
<div class="pad15">
<h2>High Level Limit</h2>
<form class="form-inline">
@@ -116,6 +151,32 @@
</form>
</div>
</div>
<div class="col-md-4 box-me entry-top-level" id="high_pressure_limit">
<div class="pad15">
<h2>High Pressure Limit</h2>
<form class="form-inline">
<div class="form-group">
<input class="form-control val_box"
type="number"
step="any"
value="<%=channels['pondlevel.high_pressure_limit'].value %>">
</div>
<a href="#"
data-confirm-message="Are you sure you want to do this?"
data-refreshpause="1"
data-command=""
data-staticsend=25.0
data-channelId="<%= channels["pondlevel.high_pressure_limit"].channelId %>"
data-techname="<%=channels["pondlevel.high_pressure_limit"].techName %>"
data-name="<%= channels["pondlevel.high_pressure_limit"].name%>"
data-nodechannelcurrentId="<%= channels["pondlevel.high_pressure_limit"].nodechannelcurrentId %>"
id="<%= channels["pondlevel.high_pressure_limit"].channelId %>"
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
</form>
</div>
</div>
</div>

View File

@@ -1,7 +1,10 @@
<div class="row row-flex">
<div class="col-xs-12">
<h1>Level</h1>
</div>
<div class="col-md-6 box-me entry-top-level" id="setrawmax">
<div class="pad15">
<h2>Raw Max (mA)</h2>
@@ -104,6 +107,114 @@
</div>
<div class="row row-flex">
<div class="col-xs-12">
<h1>Pressure</h1>
</div>
<div class="col-md-6 box-me entry-top-level" id="setpsirawmax">
<div class="pad15">
<h2>Raw Max (V)</h2>
<form class="form-inline">
<div class="form-group">
<input class="form-control val_box"
type="number"
step="any"
value="<%=channels['pondlevel.setpsirawmax'].value %>">
</div>
<a href="#"
data-confirm-message="Are you sure you want to do this?"
data-refreshpause="1"
data-command=""
data-staticsend=25.0
data-channelId="<%= channels["pondlevel.setpsirawmax"].channelId %>"
data-techname="<%=channels["pondlevel.setpsirawmax"].techName %>"
data-name="<%= channels["pondlevel.setpsirawmax"].name%>"
data-nodechannelcurrentId="<%= channels["pondlevel.setpsirawmax"].nodechannelcurrentId %>"
id="<%= channels["pondlevel.setpsirawmax"].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="setpsirawmin">
<div class="pad15">
<h2>Raw Min (V)</h2>
<form class="form-inline">
<div class="form-group">
<input class="form-control val_box"
type="number"
step="any"
value="<%=channels['pondlevel.setpsirawmin'].value %>">
</div>
<a href="#"
data-confirm-message="Are you sure you want to do this?"
data-refreshpause="1"
data-command=""
data-staticsend=25.0
data-channelId="<%= channels["pondlevel.setpsirawmin"].channelId %>"
data-techname="<%=channels["pondlevel.setpsirawmin"].techName %>"
data-name="<%= channels["pondlevel.setpsirawmin"].name%>"
data-nodechannelcurrentId="<%= channels["pondlevel.setpsirawmin"].nodechannelcurrentId %>"
id="<%= channels["pondlevel.setpsirawmin"].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="setpsieumax">
<div class="pad15">
<h2>EU Max (PSI)</h2>
<form class="form-inline">
<div class="form-group">
<input class="form-control val_box"
type="number"
step="any"
value="<%=channels['pondlevel.setpsieumax'].value %>">
</div>
<a href="#"
data-confirm-message="Are you sure you want to do this?"
data-refreshpause="1"
data-command=""
data-staticsend=25.0
data-channelId="<%= channels["pondlevel.setpsieumax"].channelId %>"
data-techname="<%=channels["pondlevel.setpsieumax"].techName %>"
data-name="<%= channels["pondlevel.setpsieumax"].name%>"
data-nodechannelcurrentId="<%= channels["pondlevel.setpsieumax"].nodechannelcurrentId %>"
id="<%= channels["pondlevel.setpsieumax"].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="seteumin">
<div class="pad15">
<h2>EU Min (PSI)</h2>
<form class="form-inline">
<div class="form-group">
<input class="form-control val_box"
type="number"
step="any"
value="<%=channels['pondlevel.setpsieumin'].value %>">
</div>
<a href="#"
data-confirm-message="Are you sure you want to do this?"
data-refreshpause="1"
data-command=""
data-staticsend=25.0
data-channelId="<%= channels["pondlevel.setpsieumin"].channelId %>"
data-techname="<%=channels["pondlevel.setpsieumin"].techName %>"
data-name="<%= channels["pondlevel.setpsieumin"].name%>"
data-nodechannelcurrentId="<%= channels["pondlevel.setpsieumin"].nodechannelcurrentId %>"
id="<%= channels["pondlevel.setpsieumin"].channelId %>"
class="btn btn-large btn-theme animated setstatic material-icons">send</a>
</form>
</div>
</div>
</div>
<style>
.box-me {

View File

@@ -9,7 +9,7 @@
</div>
</div>
<hr>
<div class='clearfix col-xs-12' style='height: 450px' id="dynamicChart" data-chart="dynamicchart" data-daysofhistory="7" data-chartlabel="Data" data-ylabel="" data-xlabel="Date" data-units="" data-channelnames="pondlevel.pond_level,pondlevel.pond_volume"></div>
<div class='clearfix col-xs-12' style='height: 450px' id="dynamicChart" data-chart="dynamicchart" data-daysofhistory="7" data-chartlabel="Data" data-ylabel="" data-xlabel="Date" data-units="" data-channelnames="pondlevel.pond_level,pondlevel.pond_volume,pondlevel.pressure_psi"></div>
<style>
.dynamic-chart-form {
background-color: whiteSmoke;

View File

@@ -5,6 +5,6 @@
},
"deviceName": "pondlevel",
"driverId": "0130",
"releaseVersion": "1",
"releaseVersion": "3",
"driverFileName": "pondlevel.py"
}

View File

@@ -0,0 +1,2 @@
class deviceBase(object):
pass

View File

@@ -12,10 +12,17 @@ pond_level = {
'value': 15.0,
'timestamp': 0
}
send_delta = 0.5
psi_reading = {
'value': 0.0,
'timestamp': 0
}
send_delta = 2.0
send_time = 300
temp_pl = pond_level['value']
temp_psi = psi_reading['value']
scaling_persist = persistence.load(filename="scaling_persist.json")
strapping_persist = persistence.load(filename="strapping_persist.json")
@@ -38,7 +45,7 @@ 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)
self.daemon = True
self.version = "1"
self.version = "3"
self.finished = threading.Event()
self.forceSend = False
threading.Thread.start(self)
@@ -48,6 +55,11 @@ class start(threading.Thread, deviceBase):
self.PL_EUMAX = 23.068
self.PL_EUMIN = 0.0
self.PSI_RAWMAX = 10.0
self.PSI_RAWMIN = 0.0
self.PSI_EUMAX = 600.0
self.PSI_EUMIN = 0.0
# Strapping table format
# {
# height: volume,
@@ -65,7 +77,7 @@ class start(threading.Thread, deviceBase):
def run(self):
"""Actually run the driver."""
global pond_level, temp_pl, send_delta, send_time
global pond_level, temp_pl, psi_reading, temp_psi, send_delta, send_time
try:
self.PL_RAWMAX = scaling_persist['raw_max']
@@ -73,9 +85,19 @@ class start(threading.Thread, deviceBase):
self.PL_EUMAX = scaling_persist['eu_max']
self.PL_EUMIN = scaling_persist['eu_min']
except KeyError:
print("No persistence data for scaling parameters.")
print("No persistence data for pond level scaling parameters.")
except TypeError:
print("No persistence data for scaling parameters.")
print("No persistence data for pond level scaling parameters.")
try:
self.PSI_RAWMAX = scaling_persist['psi_raw_max']
self.PSI_RAWMIN = scaling_persist['psi_raw_min']
self.PSI_EUMAX = scaling_persist['psi_eu_max']
self.PSI_EUMIN = scaling_persist['psi_eu_min']
except KeyError:
print("No persistence data for pressure scaling parameters.")
except TypeError:
print("No persistence data for pressure scaling parameters.")
try:
if len(strapping_persist.keys()) > 0:
@@ -100,25 +122,49 @@ class start(threading.Thread, deviceBase):
self.sendtodb("seteumax", self.PL_EUMAX, 0)
self.sendtodb("seteumin", self.PL_EUMIN, 0)
self.sendtodb("setpsirawmax", self.PSI_RAWMAX, 0)
self.sendtodb("setpsirawmin", self.PSI_RAWMIN, 0)
self.sendtodb("setpsieumax", self.PSI_EUMAX, 0)
self.sendtodb("setpsieumin", self.PSI_EUMIN, 0)
send_loops = 0
while True:
send_now = False
pl_send_now = False
psi_send_now = False
if self.forceSend:
print "FORCE SEND: TRUE"
send_now = True
pl_send_now = True
psi_send_now = True
mcu_status = self.mcu.getDict() # Gets a dictionary of the IO states
cloop_val = float(mcu_status['cloop'])
analog1_val = float(mcu_status['analog1'])
temp_pl = scale_to_eu(cloop_val, self.PL_RAWMAX, self.PL_RAWMIN, self.PL_EUMAX, self.PL_EUMIN)
temp_psi = scale_to_eu(analog1_val, self.PSI_RAWMAX, self.PSI_RAWMIN, self.PSI_EUMAX, self.PSI_EUMIN)
if abs(temp_pl - pond_level['value']) > send_delta:
print("Sending {} due to value change".format(temp_pl))
send_now = True
elif (time.time() - pond_level['timestamp']) > send_time:
print("Sending {} due to time limit".format(temp_pl))
send_now = True
# Check if pond level needs to be sent
# 4/30/2018 -- COMMENTING OUT
# Pond level was sending irregular data
# -- Patrick McDonagh
# if abs(temp_pl - pond_level['value']) > send_delta:
# print("Sending pond level {} due to value change".format(temp_pl))
# pl_send_now = True
# 4/30/2018 -- END COMMENTING OUT
if send_now:
if (time.time() - pond_level['timestamp']) > send_time:
print("Sending pond level {} due to time limit".format(temp_pl))
pl_send_now = True
# Check if pressure needs to be sent
if abs(temp_psi - psi_reading['value']) > send_delta:
print("Sending pressure psi {} due to value change".format(temp_psi))
psi_send_now = True
if (time.time() - psi_reading['timestamp']) > send_time:
print("Sending pressure psi {} due to time limit".format(temp_psi))
psi_send_now = True
if pl_send_now:
self.sendtodb('pond_level', temp_pl, 0)
pond_volume = 0.0
try:
@@ -130,6 +176,11 @@ class start(threading.Thread, deviceBase):
pond_level['value'] = temp_pl
pond_level['timestamp'] = time.time()
if psi_send_now:
self.sendtodb('pressure_psi', temp_psi, 0)
psi_reading['value'] = temp_psi
psi_reading['timestamp'] = time.time()
print("pondlevel driver still alive...")
if self.forceSend:
if send_loops > 2:
@@ -188,7 +239,11 @@ class start(threading.Thread, deviceBase):
'raw_max': self.PL_RAWMAX,
'raw_min': self.PL_RAWMIN,
'eu_max': self.PL_EUMAX,
'eu_min': self.PL_EUMIN
'eu_min': self.PL_EUMIN,
'psi_raw_max': self.PSI_RAWMAX,
'psi_raw_min': self.PSI_RAWMIN,
'psi_eu_max': self.PSI_EUMAX,
'psi_eu_min': self.PSI_EUMIN
}
persistence.store(scale_obj, filename="scaling_persist.json")
@@ -261,3 +316,31 @@ class start(threading.Thread, deviceBase):
self.sendtodb("seteumax", self.PL_EUMAX, 0)
self.store_scaling_data()
return(True)
def pondlevel_setpsirawmin(self, name, value):
"""Set the raw min pressure scaling value."""
self.PSI_RAWMIN = float(value)
self.sendtodb("setpsirawmin", self.PSI_RAWMIN, 0)
self.store_scaling_data()
return(True)
def pondlevel_setpsirawmax(self, name, value):
"""Set the raw max pressure scaling value."""
self.PSI_RAWMAX = float(value)
self.sendtodb("setpsirawmax", self.PSI_RAWMAX, 0)
self.store_scaling_data()
return(True)
def pondlevel_setpsieumin(self, name, value):
"""Set the psi min pressure scaling value."""
self.PSI_EUMIN = float(value)
self.sendtodb("setpsieumin", self.PSI_EUMIN, 0)
self.store_scaling_data()
return(True)
def pondlevel_setpsieumax(self, name, value):
"""Set the psi max pressure scaling value."""
self.PSI_EUMAX = float(value)
self.sendtodb("setpsieumax", self.PSI_EUMAX, 0)
self.store_scaling_data()
return(True)